Files
nobat724_front/components/dashboard/userAccount/detailUser/information/ButtonSendData.js
T
hamedandClaude Sonnet 4.6 1aa9f82d2a fix: resolve critical bugs and security issues across the project
- Fix GPS map links always sending literal "latitude"/"longitude" strings
  instead of actual coordinates in openLocation/Content.js
- Add api.clinic-pro.ir to next.config.js remotePatterns so production
  images load correctly
- Fix appointment page: await params and getStateInfo (Next.js 15 pattern)
- Enable 401 handling in api.js: clear cookies and redirect to /login
- Move OAuth client_secret to server-side API routes (/api/auth/token,
  /api/auth/refresh) so it is never bundled into client-side JavaScript
- Update SendReq, SubmitData, ButtonSendData to call API routes instead
  of directly sending client_secret from the browser
- Update docker-compose.yml to use server-only CLIENT_SECRET env var
- Remove debug console.log from clinic doctors list component

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-05 22:18:11 +03:30

107 lines
2.8 KiB
JavaScript

import ArrowLeftWhiteD from "@/components/icons/ArrowLeftWhiteD";
import {
changeDateType,
handleTimeExpiresToken,
removeAdditionalKeysDashboard,
} from "@/helper";
import { request } from "@/services/response";
import { Button } from "@mui/material";
import Cookies from "js-cookie";
function ButtonSendData({
loading,
errors,
information,
setInformation,
setLoading,
setErrors,
}) {
const handleErrReq = (err) => {
const errors = err?.response?.data;
if (errors) {
setErrors(typeof errors === "string" ? {} : errors);
}
setLoading(false);
};
const postData = () => {
request
.postUserProfile(changeDateType(information, false))
.then((response) => {
if (response.uuid) {
fetch("/api/auth/refresh", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ refresh_token: Cookies.get("refresh_token") }),
})
.then((r) => r.json())
.then((res) => {
if (res?.access_token) {
const expiresTime = handleTimeExpiresToken(res.expires_in);
Cookies.set("access_token", res.access_token, {
expires: expiresTime.accessTokenExpires,
path: "/",
secure: true,
sameSite: "strict",
});
}
setInformation({
...information,
prev_data: true,
uuid: response.uuid,
});
setLoading(false);
})
.catch(() => {
setLoading(false);
});
}
})
.catch((err) => {
handleErrReq(err);
});
};
const patchData = () => {
const usedKays = removeAdditionalKeysDashboard(information);
request
.patchUserProfile(
changeDateType(usedKays, true),
information?.uuid,
Cookies.get("access_token")
)
.then(() => {
setLoading(false);
})
.catch((err) => handleErrReq(err));
};
const sendReq = () => {
setLoading(true);
information.prev_data ? patchData() : postData();
};
const isDisabled = () => {
return loading || Object.values(errors).some(Boolean) || !information;
};
return (
<Button
variant="contained"
onClick={sendReq}
loading={loading}
disabled={isDisabled()}
className={`!gap-[4px] !mr-auto !text-nowrap !flex !flex-nowrap !py-[8px]
!rounded-[4px] !text-[14px] md:!text-[16px] !font-medium
!mt-[32px] sm:!mt-[38px] md:!mt-[43px] lg:!mt-[48px] !px-[16px] sm:!px-[19px] md:!px-[22px] lg:!px-[24px]
`}
>
ثبت اطلاعات
<ArrowLeftWhiteD />
</Button>
);
}
export default ButtonSendData;