So its like broken but we are rewriting status.ts & TechTable & HistoryTable

This commit is contained in:
2025-06-12 16:55:24 -05:00
parent 185a7ea500
commit 653fe64bbf
23 changed files with 2536 additions and 647 deletions

52
src/lib/hooks/status.ts Normal file
View File

@ -0,0 +1,52 @@
'use client';
import {
createClient,
type Profile,
type Result,
type Status,
} from '@/utils/supabase';
type UserWithStatus = {
user: Profile;
status: string;
created_at: string;
updated_by: Profile;
};
type PaginatedHistory = UserWithStatus[] & {
meta: {
current_page: number;
per_page: number;
total_pages: number;
total_count: number;
};
};
export const getUsersWithStatuses = async (): Promise<Result<UserWithStatus[]>> => {
try {
const supabase = createClient();
// Get only users with recent statuses (Past 7 days)
const oneWeekAgo = new Date();
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
const { data: recentStatuses, error } = await supabase
.from('statuses')
.select(`
user:profiles!user_id(*),
status,
created_at,
updated_by:profiles!updated_by_id(*)
`)
.gte('created_at', oneWeekAgo.toISOString())
.order('created_at', { ascending: false }) as {data: UserWithStatus[], error: unknown};
if (error) throw error;
if (!recentStatuses.length) return { success: true, data: []};
return { success: true, data: recentStatuses };
} catch (error) {
return { success: false, error: `Error: ${error as string}` };
}
};