submit
This commit is contained in:
1 parent
796960aeb2
commit
86a55e3cfe
1 file changed
+12
-10
@@ -7,9 +7,10 @@ import { useTheme } from "@mui/material/styles";
|
||||
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useGet } from "@/Hooks/UseApi";
|
||||
import { useGet, usePost } from "@/Hooks/UseApi";
|
||||
import { useNotificationForm } from "@/Hooks/useNotificationForm";
|
||||
import type { NotificationFormData } from "@/Validation/notifications";
|
||||
import type { Notification } from "@/Types/Notification";
|
||||
@@ -19,6 +20,7 @@ import { NotificationChannels } from "@/Types/Notification";
|
||||
const NotificationsCreatePage = () => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
const navigate = useNavigate();
|
||||
const { notificationId } = useParams<{ notificationId: string }>();
|
||||
const isEditMode = Boolean(notificationId);
|
||||
|
||||
@@ -26,6 +28,8 @@ const NotificationsCreatePage = () => {
|
||||
isEditMode ? `/notifications/${notificationId}` : null
|
||||
);
|
||||
|
||||
const { post, loading: isSubmitting } = usePost<NotificationFormData, Notification>();
|
||||
|
||||
const { schema, defaults } = useNotificationForm({ data: existingNotification });
|
||||
|
||||
const form = useForm<NotificationFormData>({
|
||||
@@ -33,12 +37,7 @@ const NotificationsCreatePage = () => {
|
||||
defaultValues: defaults,
|
||||
});
|
||||
|
||||
const {
|
||||
control,
|
||||
watch,
|
||||
reset,
|
||||
handleSubmit,
|
||||
} = form;
|
||||
const { control, watch, reset, handleSubmit } = form;
|
||||
|
||||
useEffect(() => {
|
||||
reset(defaults);
|
||||
@@ -71,8 +70,11 @@ const NotificationsCreatePage = () => {
|
||||
};
|
||||
}, [watchedType, t]);
|
||||
|
||||
const onSubmit = (data: NotificationFormData) => {
|
||||
console.log(data);
|
||||
const onSubmit = async (data: NotificationFormData) => {
|
||||
const result = await post("/notifications", data);
|
||||
if (result) {
|
||||
navigate("/notifications");
|
||||
}
|
||||
};
|
||||
|
||||
const handleTest = () => {
|
||||
@@ -232,7 +234,7 @@ const NotificationsCreatePage = () => {
|
||||
{t("common.buttons.test")}
|
||||
</Button>
|
||||
<Button
|
||||
loading={false}
|
||||
loading={isSubmitting}
|
||||
type="submit"
|
||||
variant="contained"
|
||||
color="primary"
|
||||
|
||||
Reference in new issue
Block a user