"use client"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { Dropdown } from "@/components/Dropdown"; import { useMoney } from "@/components/Money"; import type { Profile } from "@/components/ProfileForm"; import { FREQ_LABEL } from "@/lib/format"; import { createClient, updateMeta } from "@/utils/supabase/client"; const PAY_EVERY = ["WEEKLY", "BIWEEKLY", "SEMI_MONTHLY", "MONTHLY"].map((v) => ({ value: v, label: FREQ_LABEL[v] })); // Asked only when no paycheck shows up in their transactions. Saved as profile.pay, which the plan and Home read. export function PayQuestion({ profile }: { profile: Profile }) { const router = useRouter(); const { parseAmount, symbol } = useMoney(); const [amount, setAmount] = useState(""); const [every, setEvery] = useState(""); const [state, setState] = useState<"idle" | "saving" | "failed">("idle"); const n = Math.abs(parseAmount(amount)); async function save() { setState("saving"); const { error } = await updateMeta(createClient(), { data: { profile: { ...profile, pay: { amount: n, every } } } }); setState(error ? "failed" : "idle"); if (!error) router.refresh(); } return (
Couldn't save that. Try again.
}