From 6536585fe889a6f49c4517509596e6ebf42c4652 Mon Sep 17 00:00:00 2001 From: horek Date: Wed, 29 May 2024 10:37:20 +0200 Subject: [PATCH] fix: typing for swr mutation in tools instead of custom --- webapp-next/components/modals/settings.tsx | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/webapp-next/components/modals/settings.tsx b/webapp-next/components/modals/settings.tsx index 4e217ec..dc52027 100644 --- a/webapp-next/components/modals/settings.tsx +++ b/webapp-next/components/modals/settings.tsx @@ -25,6 +25,7 @@ import type { User } from "@/utils/cm2d-provider"; import { type SubmitHandler, useForm } from "react-hook-form"; import useSWRMutation from "swr/mutation"; import { useState } from "react"; +import { swrPOSTFetch } from "@/utils/tools"; type SettingsProps = { user: User; @@ -36,21 +37,13 @@ type FormChangePassword = { confirmPassword: string; }; -export async function auth(url: string, { arg }: { arg: T }) { - return fetch(url, { - method: "POST", - body: JSON.stringify(arg), - headers: { "Content-Type": "application/json" }, - }); -} - export default function SettingsModal({ user, onClose }: SettingsProps) { const { handleSubmit, register, watch, reset, - formState: { errors, isSubmitting, isSubmitSuccessful }, + formState: { errors, isSubmitting }, } = useForm(); const [isSuccessUpdateUser, setIsSuccessUpdateUser] = useState(false); @@ -68,7 +61,7 @@ export default function SettingsModal({ user, onClose }: SettingsProps) { const { trigger: triggerUpdateUser } = useSWRMutation( "/api/auth/update-user", - auth<{ username: string; password: string }> + swrPOSTFetch<{ username: string; password: string }> ); return ( @@ -179,7 +172,6 @@ export default function SettingsModal({ user, onClose }: SettingsProps) {