/* eslint-disable @typescript-eslint/no-unused-vars */ import { Button, LoadingOverlay, Modal, ModalProps, PasswordInput, TextInput, } from "@mantine/core"; import { useForm, zodResolver } from "@mantine/form"; import _ from "lodash"; import { useEffect, useRef, useState } from "react"; import { z } from "zod"; import { updateWebBid } from "../../apis/web-bid"; import { useConfirmStore } from "../../lib/zustand/use-confirm"; import { IWebBid } from "../../system/type"; export interface IWebBidModelProps extends ModalProps { data: IWebBid | null; onUpdated?: () => void; } const schema = z.object({ username: z.string().min(1, { message: "Username is required" }), password: z .string() .min(6, { message: "Password must be at least 6 characters long" }), }); export default function WebAccountModal({ data, onUpdated, ...props }: IWebBidModelProps) { const form = useForm({ validate: zodResolver(schema), }); const [loading, setLoading] = useState(false); const prevData = useRef(data); const { setConfirm } = useConfirmStore(); const handleSubmit = async (values: typeof form.values) => { if (data) { setConfirm({ title: "Update ?", message: `This account will be update`, handleOk: async () => { setLoading(true); const result = await updateWebBid(values); setLoading(false); if (!result) return; props.onClose(); if (onUpdated) { onUpdated(); } }, okButton: { color: "blue", value: "Update", }, }); } else { setLoading(true); const result = await updateWebBid(values); setLoading(false); if (!result) return; props.onClose(); if (onUpdated) { onUpdated(); } } }; useEffect(() => { form.reset(); if (!data) return; form.setValues(data); prevData.current = data; // eslint-disable-next-line react-hooks/exhaustive-deps }, [data]); useEffect(() => { if (!props.opened) { form.reset(); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [props.opened]); return ( Account} centered >
); }