put -> patch
This commit is contained in:
1 parent
86a55e3cfe
commit
830318edc3
3 files changed
+15
-6
No files matched your search
@@ -10,7 +10,7 @@ import { useParams } from "react-router-dom";
|
|||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { useGet, usePost } from "@/Hooks/UseApi";
|
import { useGet, usePost, usePatch } from "@/Hooks/UseApi";
|
||||||
import { useNotificationForm } from "@/Hooks/useNotificationForm";
|
import { useNotificationForm } from "@/Hooks/useNotificationForm";
|
||||||
import type { NotificationFormData } from "@/Validation/notifications";
|
import type { NotificationFormData } from "@/Validation/notifications";
|
||||||
import type { Notification } from "@/Types/Notification";
|
import type { Notification } from "@/Types/Notification";
|
||||||
@@ -29,6 +29,7 @@ const NotificationsCreatePage = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const { post, loading: isSubmitting } = usePost<NotificationFormData, Notification>();
|
const { post, loading: isSubmitting } = usePost<NotificationFormData, Notification>();
|
||||||
|
const { patch, loading: isPatching } = usePatch<NotificationFormData, Notification>();
|
||||||
|
|
||||||
const { schema, defaults } = useNotificationForm({ data: existingNotification });
|
const { schema, defaults } = useNotificationForm({ data: existingNotification });
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ const NotificationsCreatePage = () => {
|
|||||||
defaultValues: defaults,
|
defaultValues: defaults,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { control, watch, reset, handleSubmit } = form;
|
const { control, watch, reset, handleSubmit, clearErrors } = form;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
reset(defaults);
|
reset(defaults);
|
||||||
@@ -45,6 +46,10 @@ const NotificationsCreatePage = () => {
|
|||||||
|
|
||||||
const watchedType = watch("type");
|
const watchedType = watch("type");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
clearErrors();
|
||||||
|
}, [watchedType, clearErrors]);
|
||||||
|
|
||||||
const addressConfig = useMemo(() => {
|
const addressConfig = useMemo(() => {
|
||||||
if (watchedType === "pager_duty") {
|
if (watchedType === "pager_duty") {
|
||||||
return {
|
return {
|
||||||
@@ -71,7 +76,9 @@ const NotificationsCreatePage = () => {
|
|||||||
}, [watchedType, t]);
|
}, [watchedType, t]);
|
||||||
|
|
||||||
const onSubmit = async (data: NotificationFormData) => {
|
const onSubmit = async (data: NotificationFormData) => {
|
||||||
const result = await post("/notifications", data);
|
const result = isEditMode
|
||||||
|
? await patch(`/notifications/${notificationId}`, data)
|
||||||
|
: await post("/notifications", data);
|
||||||
if (result) {
|
if (result) {
|
||||||
navigate("/notifications");
|
navigate("/notifications");
|
||||||
}
|
}
|
||||||
@@ -234,7 +241,7 @@ const NotificationsCreatePage = () => {
|
|||||||
{t("common.buttons.test")}
|
{t("common.buttons.test")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
loading={isSubmitting}
|
loading={isSubmitting || isPatching}
|
||||||
type="submit"
|
type="submit"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
|
|||||||
@@ -1076,7 +1076,7 @@ class NetworkService {
|
|||||||
|
|
||||||
async editNotification(config) {
|
async editNotification(config) {
|
||||||
const { id, notification } = config;
|
const { id, notification } = config;
|
||||||
return this.axiosInstance.put(`/notifications/${id}`, notification);
|
return this.axiosInstance.patch(`/notifications/${id}`, notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getQueueData() {
|
async getQueueData() {
|
||||||
|
|||||||
@@ -14,7 +14,9 @@
|
|||||||
"resume": "Resume",
|
"resume": "Resume",
|
||||||
"delete": "Delete",
|
"delete": "Delete",
|
||||||
"cancel": "Cancel",
|
"cancel": "Cancel",
|
||||||
"confirm": "Confirm"
|
"confirm": "Confirm",
|
||||||
|
"save": "Save",
|
||||||
|
"test": "Test"
|
||||||
},
|
},
|
||||||
"alerts": {
|
"alerts": {
|
||||||
"pageSpeedApiKey": {
|
"pageSpeedApiKey": {
|
||||||
|
|||||||
Reference in new issue
Block a user