51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
"use client";
|
|
|
|
import { useForm } from "react-hook-form";
|
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
import { useAlertStore } from "@/shared/lib/use-alert-store";
|
|
import { ENDPOINT } from "@/shared/config";
|
|
import {
|
|
authorizationFormSchema,
|
|
type AuthorizationFormData,
|
|
} from "../model/authorizations-interface";
|
|
import { AuthorizationsApi } from "../api/authorization-service";
|
|
import { ModuleForm } from "./module-form";
|
|
|
|
function ModifyPage({ sequential }: { sequential: string }) {
|
|
const { setMessage: alert } = useAlertStore((state) => state);
|
|
|
|
const { data: authorizationInfo } = useQuery({
|
|
queryKey: [ENDPOINT.USER_SERVICE.AUTHORIZATIONS, sequential],
|
|
queryFn: () => AuthorizationsApi.getAuthorizationInfo(sequential),
|
|
});
|
|
|
|
const { mutateAsync: updateAuthorization } = useMutation({
|
|
mutationFn: (data: AuthorizationFormData) =>
|
|
AuthorizationsApi.updateAuthorization(sequential, data),
|
|
onSuccess: () => {
|
|
alert("수정되었습니다.");
|
|
},
|
|
});
|
|
|
|
const form = useForm<AuthorizationFormData>({
|
|
resolver: zodResolver(authorizationFormSchema),
|
|
values: authorizationInfo,
|
|
});
|
|
|
|
return (
|
|
<div className="card card-border !mt-6">
|
|
<div className="card-header">
|
|
<h3 className="text-2xl font-medium text-label">모듈API 수정</h3>
|
|
</div>
|
|
<ModuleForm
|
|
form={form}
|
|
authorizationNo={parseInt(sequential)}
|
|
handleSave={updateAuthorization}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export { ModifyPage };
|