Commit fb3d2e9c by Arjun Jhukal

updated the functionality for the update page

parent 84e32cf0
...@@ -26,6 +26,7 @@ export default function AddPageForm({ id }: { id?: string }) { ...@@ -26,6 +26,7 @@ export default function AddPageForm({ id }: { id?: string }) {
}) })
const [updatedPage, { isLoading: updating }] = useUpdatePageByIdMutation(); const [updatedPage, { isLoading: updating }] = useUpdatePageByIdMutation();
console.log("single page data", data);
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const router = useRouter(); const router = useRouter();
const formik = useFormik({ const formik = useFormik({
...@@ -66,6 +67,27 @@ export default function AddPageForm({ id }: { id?: string }) { ...@@ -66,6 +67,27 @@ export default function AddPageForm({ id }: { id?: string }) {
if (id) {
try {
const response = await updatedPage({ id, body: formData }).unwrap();
dispatch(
showToast({
message: response.message || "Page created successfully",
variant: ToastVariant.SUCCESS
})
);
router.push("/pages");
} catch (e: any) {
console.error("Error submitting form:", e);
dispatch(
showToast({
message: e.message || "Something went wrong",
variant: ToastVariant.ERROR
})
);
}
}
else {
try { try {
const response = await createPage(formData).unwrap(); const response = await createPage(formData).unwrap();
dispatch( dispatch(
...@@ -85,6 +107,7 @@ export default function AddPageForm({ id }: { id?: string }) { ...@@ -85,6 +107,7 @@ export default function AddPageForm({ id }: { id?: string }) {
); );
} }
} }
}
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment