{ - const accessTokenExpires = new Date(); - accessTokenExpires.setSeconds( - accessTokenExpires.getSeconds() + response.expires_in - ); - const refreshTokenExpires = new Date(); - refreshTokenExpires.setDate(refreshTokenExpires.getDate() + 30); + const expiresTime = handleTimeExpiresToken(response.expires_in); Cookies.set("access_token", response.access_token, { - expires: accessTokenExpires, + expires: expiresTime.accessTokenExpires, path: "/", secure: true, sameSite: "strict", }); Cookies.set("refresh_token", response.refresh_token, { - expires: refreshTokenExpires, + expires: expiresTime.refreshTokenExpires, path: "/", secure: true, sameSite: "strict", }); Cookies.set("uuid", uuid, { - expires: refreshTokenExpires, + expires: expiresTime.refreshTokenExpires, path: "/", secure: true, sameSite: "strict", diff --git a/helper/index.js b/helper/index.js index 6d9fe58..111dd4c 100644 --- a/helper/index.js +++ b/helper/index.js @@ -123,17 +123,15 @@ export const formatPhoneNumber = (input) => { }; export function validatePhoneNumber(input) { - const digits = input.replace(/\D/g, ""); - - if (!digits) { + if (!input) { return { valid: false, text: "شماره موبایل نمیتواند خالی باشد." }; } - if (digits.length !== 9) { + if (input.length !== 11) { return { valid: false, text: "شماره موبایل باید دقیقا 11 رقم باشد." }; } - const isValid = /^[1-9]\d{8}$/.test(digits); + const isValid = /^09\d{9}$/.test(input); if (!isValid) { return { valid: false, text: "شماره موبایل نامعتبر است." }; } @@ -185,8 +183,6 @@ export function getCleanNumberValue(value, defaultValue = 0) { return isNaN(number) ? defaultValue : number; } -export const changeNumToDefault = (num) => `09${num.replace(/\D/g, "")}`; - export function hasDataChanged(previousData, newData) { const oldDataString = JSON.stringify( previousData, @@ -201,3 +197,30 @@ export const getParsedUserInfo = () => { const parsedUserInfo = user && JSON.parse(user); return parsedUserInfo; }; + +export const handleTimeExpiresToken = (expires_in) => { + const accessTokenExpires = new Date(); + accessTokenExpires.setSeconds(accessTokenExpires.getSeconds() + expires_in); + const refreshTokenExpires = new Date(); + refreshTokenExpires.setDate(refreshTokenExpires.getDate() + 30); + + return { + accessTokenExpires, + refreshTokenExpires, + }; +}; + +export const removeAdditionalKeysDashboard = (information) => { + const { + national_code, + changed, + created, + id, + status, + prev_data, + uuid, + ...usedKays + } = information; + + return usedKays; +}; diff --git a/services/response.js b/services/response.js index 5df3556..6f29e83 100644 --- a/services/response.js +++ b/services/response.js @@ -29,10 +29,22 @@ export const request = { }, }); }, + postRefreshToken: (formData) => { + return api.post("oauth/token", formData, { + headers: { + "Content-Type": "application/x-www-form-urlencoded", + Authorization: "", + }, + }); + }, getUserProfile: (uuid) => api.get(`/api/v1/user-profile/${uuid}`), postUserProfile: (data) => api.post("api/v1/user-profile", data), - patchUserProfile: (data, uuid) => - api.patch(`api/v1/user-profile/${uuid}`, data), + patchUserProfile: (data, uuid, token) => + api.patch(`api/v1/user-profile/${uuid}`, data, { + headers: { + Authorization: `Bearer ${token}`, + }, + }), getUserInfo: (headers) => api.get("oauth/userinfo", headers), getInsuranceType: () => api.get("api/v1/categorys/insurance_type", { @@ -40,4 +52,12 @@ export const request = { Authorization: "", }, }), + getAppointmentWeeklySchedule: (uuid) => + api.get(`api/v1/appointment-settings/weekly-schedule/${uuid}`), + postAppointmentWeeklySchedule: () => + api.post("api/v1/appointment-settings/weekly-schedule/"), + patchAppointmentWeeklySchedule: (uuid) => + api.patch(`api/v1/appointment-settings/weekly-schedule/${uuid}`), + deleteAppointmentWeeklySchedule: (uuid) => + api.delete(`api/v1/appointment-settings/weekly-schedule/${uuid}`), };