Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
37c443fe6a
commit
6297c81d22
@@ -9,6 +9,7 @@ import { supabase } from "@/integrations/supabase/client";
|
||||
import { useAuth } from "@/lib/auth";
|
||||
import { Plus, Trash2, Loader2 } from "lucide-react";
|
||||
import { formatCurrency, formatDate } from "@/lib/format";
|
||||
import { roundToTenth } from "@/lib/timer";
|
||||
import { toast } from "sonner";
|
||||
|
||||
export function CaseTimeTab({ caseRecord }: { caseRecord: any }) {
|
||||
@@ -16,6 +17,7 @@ export function CaseTimeTab({ caseRecord }: { caseRecord: any }) {
|
||||
const [entries, setEntries] = useState<any[]>([]);
|
||||
const [showForm, setShowForm] = useState(false);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [profileRate, setProfileRate] = useState<number | null>(null);
|
||||
const [form, setForm] = useState({
|
||||
work_date: new Date().toISOString().slice(0, 10),
|
||||
hours: "",
|
||||
@@ -35,9 +37,23 @@ export function CaseTimeTab({ caseRecord }: { caseRecord: any }) {
|
||||
|
||||
useEffect(() => { load(); }, [caseRecord.id]);
|
||||
|
||||
// Pull this user's default hourly rate; use it to prefill when case has no override.
|
||||
useEffect(() => {
|
||||
if (!user?.id) return;
|
||||
(async () => {
|
||||
const { data } = await supabase.from("profiles").select("hourly_rate").eq("id", user.id).maybeSingle();
|
||||
const rate = (data as any)?.hourly_rate ?? null;
|
||||
setProfileRate(rate);
|
||||
if (!caseRecord.default_hourly_rate && rate != null) {
|
||||
setForm((f) => (f.hourly_rate ? f : { ...f, hourly_rate: String(rate) }));
|
||||
}
|
||||
})();
|
||||
}, [user?.id, caseRecord.default_hourly_rate]);
|
||||
|
||||
const submit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
const hours = parseFloat(form.hours);
|
||||
const rawHours = parseFloat(form.hours);
|
||||
const hours = roundToTenth(rawHours);
|
||||
const rate = parseFloat(form.hourly_rate || "0");
|
||||
if (!hours || hours <= 0) { toast.error("Hours must be greater than 0"); return; }
|
||||
if (!form.description.trim()) { toast.error("Description required"); return; }
|
||||
|
||||
Reference in New Issue
Block a user