diff --git a/src/app/admin/MemberForm.tsx b/src/app/admin/MemberForm.tsx index 2a8456c9..a4296635 100644 --- a/src/app/admin/MemberForm.tsx +++ b/src/app/admin/MemberForm.tsx @@ -2,25 +2,32 @@ import Autocomplete from '@/components/Autocomplete'; import { fetcher } from '@/lib/fetcher'; -import { useState } from 'react'; +import { useRouter } from 'next/navigation'; +import { useEffect, useState } from 'react'; import useSWRMutation from 'swr/mutation'; import type { Member } from './page'; const getMemberStr = (member: Member) => `${member.email} - ${member.firstName} ${member.lastName}`; function MemberDetail({ member }: { member: Member }) { - const { paid, ...details } = member; - const [payment, setPayment] = useState(member.paid); + useEffect(() => { + setPayment(member.paid); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [member.id]); + + const router = useRouter(); const updatePayment = useSWRMutation('payment', fetcher.put.mutate, { onSuccess: () => { setPayment(!payment); + router.refresh(); }, }); const handlePaymentChange = () => { updatePayment.trigger({ id: member.id, paid: !payment }); }; + const { paid, ...details } = member; return (