Skip to content

Commit

Permalink
fix(admin): update member payment checkbox properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jsun969 committed Feb 18, 2024
1 parent a5d393d commit 1ee43bb
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/app/admin/MemberForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<table className="relative [&>tbody>*>*]:border [&>tbody>*>*]:border-grey [&>tbody>*>*]:px-4 [&>tbody>*>*]:py-2">
<tbody>
Expand Down

0 comments on commit 1ee43bb

Please sign in to comment.