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,23 +67,45 @@ export default function AddPageForm({ id }: { id?: string }) { ...@@ -66,23 +67,45 @@ export default function AddPageForm({ id }: { id?: string }) {
try { if (id) {
const response = await createPage(formData).unwrap(); try {
dispatch( const response = await updatedPage({ id, body: formData }).unwrap();
showToast({ dispatch(
message: response.message || "Page created successfully", showToast({
variant: ToastVariant.SUCCESS message: response.message || "Page created successfully",
}) variant: ToastVariant.SUCCESS
); })
router.push("/pages"); );
} catch (e: any) { router.push("/pages");
console.error("Error submitting form:", e); } catch (e: any) {
dispatch( console.error("Error submitting form:", e);
showToast({ dispatch(
message: e.message || "Something went wrong", showToast({
variant: ToastVariant.ERROR message: e.message || "Something went wrong",
}) variant: ToastVariant.ERROR
); })
);
}
}
else {
try {
const response = await createPage(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
})
);
}
} }
} }
......
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