Skip to content

Commit

Permalink
refactor: refactor DeleteLineForm component
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorzpokorski committed Nov 27, 2023
1 parent 17a461a commit 94a3ddf
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/ui/components/DeleteLineForm/DeleteLineForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ type Props = {
};

export const DeleteLineForm = ({ lineId, checkoutId }: Props) => {
const deleteLineAction = async (lineId: string, checkoutId: string) => {
const deleteLineAction = async (formData: FormData) => {
"use server";

const lineId = formData.get("lineId")?.toString();
const checkoutId = formData.get("checkoutId")?.toString();

if (!checkoutId || !lineId) {
throw Error("Miss `lineId` and/or `checkoutId`.");
}

await executeGraphQL(CheckoutDeleteLinesDocument, {
variables: {
checkoutId,
Expand All @@ -23,10 +30,10 @@ export const DeleteLineForm = ({ lineId, checkoutId }: Props) => {
revalidatePath("/cart");
};

const deleteLineActionWithArgs = deleteLineAction.bind(null, lineId, checkoutId);

return (
<form action={deleteLineActionWithArgs}>
<form action={deleteLineAction}>
<input type="hidden" name="checkoutId" value={checkoutId} />
<input type="hidden" name="lineId" value={lineId} />
<SubmitButton />
</form>
);
Expand Down

0 comments on commit 94a3ddf

Please sign in to comment.