Skip to content

Commit d6f4096

Browse files
refactor: refactor DeleteLineForm component
1 parent d078df1 commit d6f4096

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/ui/components/DeleteLineForm/DeleteLineForm.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ type Props = {
99
};
1010

1111
export const DeleteLineForm = ({ lineId, checkoutId }: Props) => {
12-
const deleteLineAction = async (lineId: string, checkoutId: string) => {
12+
const deleteLineAction = async (formData: FormData) => {
1313
"use server";
1414

15+
const lineId = formData.get("lineId")?.toString();
16+
const checkoutId = formData.get("checkoutId")?.toString();
17+
18+
if (!checkoutId || !lineId) {
19+
throw Error("Miss `lineId` and/or `checkoutId`.");
20+
}
21+
1522
await executeGraphQL(CheckoutDeleteLinesDocument, {
1623
variables: {
1724
checkoutId,
@@ -23,10 +30,10 @@ export const DeleteLineForm = ({ lineId, checkoutId }: Props) => {
2330
revalidatePath("/cart");
2431
};
2532

26-
const deleteLineActionWithArgs = deleteLineAction.bind(null, lineId, checkoutId);
27-
2833
return (
29-
<form action={deleteLineActionWithArgs}>
34+
<form action={deleteLineAction}>
35+
<input type="hidden" name="checkoutId" value={checkoutId} />
36+
<input type="hidden" name="lineId" value={lineId} />
3037
<SubmitButton />
3138
</form>
3239
);

0 commit comments

Comments
 (0)