feat: add expert search, legal search and UI improvements

This commit is contained in:
Aktraiser 2024-12-30 13:34:26 +01:00
parent 2c5ca94b3c
commit 271199c527
53 changed files with 4595 additions and 708 deletions

38
ui/lib/config.ts Normal file
View file

@ -0,0 +1,38 @@
// Inspiré de la structure du backend mais adapté pour le frontend
interface Config {
GENERAL: {
WS_URL: string;
API_URL: string;
};
SUPABASE: {
URL: string;
ANON_KEY: string;
};
}
// Fonctions utilitaires pour la configuration
export const getSupabaseUrl = (): string =>
process.env.NEXT_PUBLIC_SUPABASE_URL || '';
export const getSupabaseKey = (): string =>
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || '';
export const getApiUrl = (): string =>
process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001/api';
export const getWsUrl = (): string =>
process.env.NEXT_PUBLIC_WS_URL || 'ws://localhost:3001';
// Configuration complète
export const config: Config = {
GENERAL: {
WS_URL: getWsUrl(),
API_URL: getApiUrl(),
},
SUPABASE: {
URL: getSupabaseUrl(),
ANON_KEY: getSupabaseKey(),
},
};
export default config;

62
ui/lib/supabase.ts Normal file
View file

@ -0,0 +1,62 @@
import { createClient } from '@supabase/supabase-js';
import { getSupabaseUrl, getSupabaseKey } from '@/lib/config';
const supabaseUrl = getSupabaseUrl();
const supabaseKey = getSupabaseKey();
if (!supabaseUrl || !supabaseKey) {
throw new Error('Missing Supabase credentials');
}
export const supabase = createClient(supabaseUrl, supabaseKey);
// Fonction de test de connexion
export async function checkSupabaseConnection() {
try {
const { data, error } = await supabase
.from('experts')
.select('*')
.limit(1);
if (error) throw error;
console.log('✅ Frontend Supabase connection successful');
return true;
} catch (error) {
console.error('❌ Frontend Supabase connection error:', error);
return false;
}
}
export async function uploadExpertImage(file: File, expertId: string) {
try {
const fileExt = file.name.split('.').pop();
const fileName = `${expertId}-main.${fileExt}`;
const filePath = `experts/${fileName}`;
const { error: uploadError } = await supabase.storage
.from('expert-images') // Créez ce bucket dans Supabase
.upload(filePath, file, {
upsert: true
});
if (uploadError) throw uploadError;
// Obtenir l'URL publique
const { data: { publicUrl } } = supabase.storage
.from('expert-images')
.getPublicUrl(filePath);
// Mettre à jour l'expert avec l'URL de l'image
const { error: updateError } = await supabase
.from('experts')
.update({ image_url: publicUrl })
.eq('id_expert', expertId);
if (updateError) throw updateError;
return publicUrl;
} catch (error) {
console.error('Error uploading image:', error);
throw error;
}
}

View file

@ -1,7 +1,9 @@
import clsx, { ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge';
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
export const cn = (...classes: ClassValue[]) => twMerge(clsx(...classes));
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
export const formatTimeDifference = (
date1: Date | string,