Skip to content

Commit

Permalink
fix: typing for swr mutation in tools instead of custom
Browse files Browse the repository at this point in the history
  • Loading branch information
HoreKk committed May 29, 2024
1 parent 7ae7e12 commit 6536585
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions webapp-next/components/modals/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,21 +37,13 @@ type FormChangePassword = {
confirmPassword: string;
};

export async function auth<T>(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<FormChangePassword>();

const [isSuccessUpdateUser, setIsSuccessUpdateUser] = useState(false);
Expand All @@ -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 (
Expand Down Expand Up @@ -179,7 +172,6 @@ export default function SettingsModal({ user, onClose }: SettingsProps) {
<CloseButton
alignSelf="flex-start"
position="absolute"
// align center vertically
top="50%"
transform="translateY(-50%)"
right={2}
Expand Down

0 comments on commit 6536585

Please sign in to comment.