916ad39176
Deploy to route.crispygoat.com / deploy (push) Failing after 3m1s
- Add MinIO/S3-compatible storage client (src/lib/storage.ts) with uploadObject, deleteObject, presigned URL helpers, and BUCKETS constant - Wire product images, brand logos, and water log photos to MinIO via the new storage client - Migrate forgot-password to Neon Auth (remove Supabase /auth/v1/recover call) - Migrate send-scheduled cron to direct Postgres + Resend (remove Supabase Edge Function proxy) - Add logoUrl to email types (OrderReceipt, Welcome, PasswordReset) and pass brand_settings.logo_url from all call sites - Update email templates to use dynamic logoUrl instead of hardcoded Supabase bucket URLs - Remove hardcoded Supabase URLs from TuxedoVideoHero, TuxedoAboutPage, TimeTrackingFieldClient; use brand_settings props + local public/ fallback - Download brand logos (3) and tuxedo-hero.mp4 (36MB) from Supabase bucket to public/ for local development - Add MinIO env vars to .env.example (endpoint, access key, secret, buckets) - Fix TimeTrackingFieldClient to destructure logoUrl and brandAccent props - Fix admin/users.ts logoUrl type (null → undefined for optional string) - Remove stale sb- cookie from wholesale-auth - Migrate tuxedo/about page to remove supabase import and use pool query for wholesale_settings lookup
258 lines
8.9 KiB
TypeScript
258 lines
8.9 KiB
TypeScript
"use server";
|
|
|
|
import { getAdminUser } from "@/lib/admin-permissions";
|
|
|
|
// TODO(migration): the time-tracking admin RPCs (get_time_tracking_workers,
|
|
// create_time_worker, reset_time_worker_pin, update_time_worker,
|
|
// delete_time_worker, create_time_task, update_time_task,
|
|
// delete_time_task, get_worker_time_logs, update_worker_time_log,
|
|
// delete_worker_time_log, get_time_tracking_summary,
|
|
// get_time_tracking_settings, update_time_tracking_settings,
|
|
// get_time_tracking_notification_log, check_and_notify_overtime) and
|
|
// the underlying tables (`time_workers`, `time_tasks`, `time_logs`,
|
|
// `time_tracking_settings`, `time_tracking_notification_log`) were
|
|
// not carried over into the SaaS rebuild's `db/schema/`. The actions
|
|
// below return empty results. To bring time tracking back, add
|
|
// the tables to `db/schema/` and re-implement against Drizzle. See
|
|
// `actions/route-trace/lots.ts` for the same pattern.
|
|
|
|
// ── Types ─────────────────────────────────────────────────────────────────────
|
|
|
|
export type TimeWorker = {
|
|
id: string;
|
|
brand_id: string;
|
|
name: string;
|
|
role: string;
|
|
lang: string;
|
|
pin: string;
|
|
active: boolean;
|
|
last_used_at: string | null;
|
|
created_at: string;
|
|
worker_number: number | null;
|
|
};
|
|
|
|
export type TimeTask = {
|
|
id: string;
|
|
name: string;
|
|
name_es: string | null;
|
|
unit: string;
|
|
active: boolean;
|
|
sort_order: number;
|
|
};
|
|
|
|
export type TimeLog = {
|
|
id: string;
|
|
worker_id: string;
|
|
worker_name: string;
|
|
task_id: string | null;
|
|
task_name: string;
|
|
clock_in: string;
|
|
clock_out: string | null;
|
|
lunch_break_minutes: number;
|
|
notes: string | null;
|
|
submitted_via: string;
|
|
total_minutes: number;
|
|
created_at: string;
|
|
};
|
|
|
|
export type TimeSummary = {
|
|
by_worker: { id: string; name: string; entry_count: number; total_hours: number }[];
|
|
by_task: { id: string; name: string; name_es: string | null; entry_count: number; total_hours: number }[];
|
|
totals: { entry_count: number; total_hours: number; open_count: number };
|
|
};
|
|
|
|
// ── Workers ───────────────────────────────────────────────────────────────────
|
|
|
|
export async function getTimeTrackingWorkers(_brandId: string): Promise<TimeWorker[]> {
|
|
// Time tracking tables not in SaaS rebuild — return empty list.
|
|
return [];
|
|
}
|
|
|
|
export async function createTimeWorker(
|
|
_brandId: string,
|
|
_name: string,
|
|
_role = "worker",
|
|
_lang = "en"
|
|
): Promise<{ success: boolean; worker?: TimeWorker; pin?: string; error?: string }> {
|
|
const adminUser = await getAdminUser();
|
|
if (!adminUser) return { success: false, error: "Not authenticated" };
|
|
return { success: false, error: "Time tracking is not configured" };
|
|
}
|
|
|
|
export async function resetTimeWorkerPin(_workerId: string): Promise<{ success: boolean; pin?: string; error?: string }> {
|
|
const adminUser = await getAdminUser();
|
|
if (!adminUser) return { success: false, error: "Not authenticated" };
|
|
return { success: false, error: "Time tracking is not configured" };
|
|
}
|
|
|
|
export async function updateTimeWorker(
|
|
_workerId: string,
|
|
_name: string,
|
|
_role: string,
|
|
_lang: string,
|
|
_active: boolean
|
|
): Promise<{ success: boolean; error?: string }> {
|
|
const adminUser = await getAdminUser();
|
|
if (!adminUser) return { success: false, error: "Not authenticated" };
|
|
return { success: false, error: "Time tracking is not configured" };
|
|
}
|
|
|
|
export async function deleteTimeWorker(_workerId: string): Promise<{ success: boolean; error?: string }> {
|
|
const adminUser = await getAdminUser();
|
|
if (!adminUser) return { success: false, error: "Not authenticated" };
|
|
return { success: false, error: "Time tracking is not configured" };
|
|
}
|
|
|
|
// ── Tasks ────────────────────────────────────────────────────────────────────
|
|
|
|
export async function getTimeTrackingTasks(_brandId: string, _activeOnly = false): Promise<TimeTask[]> {
|
|
return [];
|
|
}
|
|
|
|
export async function createTimeTask(
|
|
_brandId: string,
|
|
_name: string,
|
|
_nameEs: string | null = null,
|
|
_unit = "hours",
|
|
_sortOrder = 0
|
|
): Promise<{ success: boolean; id?: string; error?: string }> {
|
|
const adminUser = await getAdminUser();
|
|
if (!adminUser) return { success: false, error: "Not authenticated" };
|
|
return { success: false, error: "Time tracking is not configured" };
|
|
}
|
|
|
|
export async function updateTimeTask(
|
|
_taskId: string,
|
|
_name: string,
|
|
_nameEs: string,
|
|
_unit: string,
|
|
_active: boolean,
|
|
_sortOrder: number
|
|
): Promise<{ success: boolean; error?: string }> {
|
|
const adminUser = await getAdminUser();
|
|
if (!adminUser) return { success: false, error: "Not authenticated" };
|
|
return { success: false, error: "Time tracking is not configured" };
|
|
}
|
|
|
|
export async function deleteTimeTask(_taskId: string): Promise<{ success: boolean; error?: string }> {
|
|
const adminUser = await getAdminUser();
|
|
if (!adminUser) return { success: false, error: "Not authenticated" };
|
|
return { success: false, error: "Time tracking is not configured" };
|
|
}
|
|
|
|
// ── Time Logs ─────────────────────────────────────────────────────────────────
|
|
|
|
export async function getWorkerTimeLogs(
|
|
_brandId: string,
|
|
_options: {
|
|
workerId?: string;
|
|
taskId?: string;
|
|
start?: string;
|
|
end?: string;
|
|
limit?: number;
|
|
offset?: number;
|
|
} = {}
|
|
): Promise<TimeLog[]> {
|
|
return [];
|
|
}
|
|
|
|
export async function updateWorkerTimeLog(
|
|
_logId: string,
|
|
_taskName: string,
|
|
_clockIn: string,
|
|
_clockOut: string | null,
|
|
_lunchMinutes: number,
|
|
_notes: string | null
|
|
): Promise<{ success: boolean; error?: string }> {
|
|
const adminUser = await getAdminUser();
|
|
if (!adminUser) return { success: false, error: "Not authenticated" };
|
|
return { success: false, error: "Time tracking is not configured" };
|
|
}
|
|
|
|
export async function deleteWorkerTimeLog(_logId: string): Promise<{ success: boolean; error?: string }> {
|
|
const adminUser = await getAdminUser();
|
|
if (!adminUser) return { success: false, error: "Not authenticated" };
|
|
return { success: false, error: "Time tracking is not configured" };
|
|
}
|
|
|
|
export async function getTimeTrackingSummary(
|
|
_brandId: string,
|
|
_start: string,
|
|
_end: string
|
|
): Promise<TimeSummary> {
|
|
return { by_worker: [], by_task: [], totals: { entry_count: 0, total_hours: 0, open_count: 0 } };
|
|
}
|
|
|
|
// ── Time Tracking Settings ─────────────────────────────────────────────────────
|
|
|
|
export type TimeTrackingSettings = {
|
|
id: string;
|
|
brand_id: string;
|
|
pay_period_start_day: number;
|
|
pay_period_length_days: number;
|
|
daily_overtime_threshold: number;
|
|
weekly_overtime_threshold: number;
|
|
overtime_multiplier: number;
|
|
overtime_notifications: boolean;
|
|
notification_emails: string[];
|
|
notification_sms_numbers: string[];
|
|
enable_daily_alerts: boolean;
|
|
enable_weekly_alerts: boolean;
|
|
daily_alert_threshold: number;
|
|
weekly_alert_threshold: number;
|
|
send_end_of_period_summary: boolean;
|
|
brand_name: string;
|
|
};
|
|
|
|
export async function getTimeTrackingSettings(_brandId: string): Promise<TimeTrackingSettings | null> {
|
|
// Real RPC not in SaaS rebuild.
|
|
return null;
|
|
}
|
|
|
|
export async function updateTimeTrackingSettings(
|
|
_brandId: string,
|
|
_settings: {
|
|
pay_period_start_day: number;
|
|
pay_period_length_days: number;
|
|
daily_overtime_threshold: number;
|
|
weekly_overtime_threshold: number;
|
|
overtime_multiplier: number;
|
|
overtime_notifications: boolean;
|
|
notification_emails?: string[];
|
|
notification_sms_numbers?: string[];
|
|
enable_daily_alerts?: boolean;
|
|
enable_weekly_alerts?: boolean;
|
|
daily_alert_threshold?: number;
|
|
weekly_alert_threshold?: number;
|
|
send_end_of_period_summary?: boolean;
|
|
brand_name?: string;
|
|
}
|
|
): Promise<{ success: boolean; error?: string }> {
|
|
const adminUser = await getAdminUser();
|
|
if (!adminUser) return { success: false, error: "Not authenticated" };
|
|
return { success: false, error: "Time tracking is not configured" };
|
|
}
|
|
|
|
// ── Notification Log ─────────────────────────────────────────────────────────
|
|
|
|
export type NotificationLogEntry = {
|
|
id: string;
|
|
worker_id: string | null;
|
|
worker_name: string | null;
|
|
trigger_type: string;
|
|
threshold_hours: number | null;
|
|
actual_hours: number | null;
|
|
emails_sent: string[];
|
|
sms_numbers_sent: string[];
|
|
email_sent: boolean;
|
|
sms_sent: boolean;
|
|
error_message: string | null;
|
|
created_at: string;
|
|
};
|
|
|
|
export async function getTimeTrackingNotificationLog(
|
|
_brandId: string,
|
|
_limit = 100
|
|
): Promise<NotificationLogEntry[]> {
|
|
return [];
|
|
} |