import { useState } from "react"; import ButtonFixed from "../paying/ButtonFixed"; import { Button } from "@mui/material"; import ArrowLeftB from "@/components/icons/ArrowLeftB"; import { request } from "@/services/response"; function SubmitData({ setStep, data, prevData }) { const [loading, setLoading] = useState(false); const newStep = () => setStep((prev) => prev + 1); const handleSubmit = () => { const isChanged = JSON.stringify(prevData) !== JSON.stringify(data); if (isChanged) { setLoading(true); let newData = data; const { basic_insurance, name, national_code, uuid } = newData; newData = { basic_insurance: [basic_insurance.value?.id], ...(prevData.name?.value === data.name.value ? {} : { name: name }), ...(prevData.national_code?.value ? {} : { national_code: national_code }), }; request .patchUserProfile(newData, uuid) .then(() => { setLoading(false); newStep(); }) .catch(() => { setLoading(false); }); } else { newStep(); } }; return ( ); } export default SubmitData;