diff --git a/app/component/Field.js b/app/component/Field.js index d7f3cb5..5a3e0f2 100644 --- a/app/component/Field.js +++ b/app/component/Field.js @@ -14,7 +14,7 @@ function Field({

- {user.name}{" "} + {userInfo.realName}{" "} عزیز! @@ -18,12 +20,6 @@ function Head({ user }) { در این قسمت میتوانید اطلاعات حساب خود و نوبت های گرفته شده را مدیریت کنید.{" "}

-
{ + const newData = data; + const splitedDate = newData.birthday.split("/"); + newData.birthday = convertJalaliTimestamp( + { + jy: Number(splitedDate[0]), + jm: Number(splitedDate[1]), + jd: Number(splitedDate[2]), + }, + true + ); + return newData; + }; + const postData = () => { + console.log(changeDateType(information)); + request .postUserProfile(information) .then((response) => { @@ -67,6 +84,7 @@ function ButtonSendData({ const patchData = () => { const usedKays = removeAdditionalKeysDashboard(information); + console.log(changeDateType(information)); request .patchUserProfile( diff --git a/components/dashboard/userAccount/detailUser/information/Content.js b/components/dashboard/userAccount/detailUser/information/form/Content.js similarity index 100% rename from components/dashboard/userAccount/detailUser/information/Content.js rename to components/dashboard/userAccount/detailUser/information/form/Content.js diff --git a/components/dashboard/userAccount/detailUser/information/DateBirthday.js b/components/dashboard/userAccount/detailUser/information/form/DateBirthday.js similarity index 100% rename from components/dashboard/userAccount/detailUser/information/DateBirthday.js rename to components/dashboard/userAccount/detailUser/information/form/DateBirthday.js diff --git a/components/dashboard/userAccount/detailUser/information/disease.js b/components/dashboard/userAccount/detailUser/information/form/disease.js similarity index 100% rename from components/dashboard/userAccount/detailUser/information/disease.js rename to components/dashboard/userAccount/detailUser/information/form/disease.js diff --git a/components/dashboard/userAccount/detailUser/information/Form.js b/components/dashboard/userAccount/detailUser/information/form/index.js similarity index 98% rename from components/dashboard/userAccount/detailUser/information/Form.js rename to components/dashboard/userAccount/detailUser/information/form/index.js index 5e6f911..0afe4b1 100644 --- a/components/dashboard/userAccount/detailUser/information/Form.js +++ b/components/dashboard/userAccount/detailUser/information/form/index.js @@ -1,8 +1,8 @@ import { getParsedUserInfo } from "@/helper"; import Content from "./Content"; import DateBirthday from "./DateBirthday"; -import AutoSelector from "./component/AutoSelector"; -import Field from "./component/Field"; +import AutoSelector from "../component/AutoSelector"; +import Field from "../component/Field"; import { gender, blood_group, @@ -20,6 +20,8 @@ function Form({ insurance, errors, changeData, information }) { list.find((g) => g.id === information[name]); const parsedUserInfo = getParsedUserInfo(); + console.log(information); + return (
diff --git a/components/dashboard/userAccount/detailUser/information/listSelector.js b/components/dashboard/userAccount/detailUser/information/form/listSelector.js similarity index 87% rename from components/dashboard/userAccount/detailUser/information/listSelector.js rename to components/dashboard/userAccount/detailUser/information/form/listSelector.js index b2f3aba..178c785 100644 --- a/components/dashboard/userAccount/detailUser/information/listSelector.js +++ b/components/dashboard/userAccount/detailUser/information/form/listSelector.js @@ -31,9 +31,3 @@ export const job = [ { label: "آزاد", id: "azad" }, { label: "دولتی", id: "dolati" }, ]; - -export const insurance = [ - { label: "بیمه 1", id: 10 }, - { label: "بیمه 2", id: 20 }, - { label: "بیمه 3", id: 30 }, -]; diff --git a/components/dashboard/userAccount/detailUser/information/index.js b/components/dashboard/userAccount/detailUser/information/index.js index 13da818..4a7225e 100644 --- a/components/dashboard/userAccount/detailUser/information/index.js +++ b/components/dashboard/userAccount/detailUser/information/index.js @@ -1,9 +1,9 @@ import { useEffect, useState } from "react"; -import Form from "./Form"; +import Form from "./form"; import { request } from "@/services/response"; import ButtonSendData from "./ButtonSendData"; import { getParsedUserInfo } from "@/helper"; -import { disease } from "../information/disease"; +import { disease } from "./form/disease"; function Information({ information, setInformation }) { const [loading, setLoading] = useState(false); diff --git a/components/dashboard/userAccount/detailUser/relatives/ItemRelatives.js b/components/dashboard/userAccount/detailUser/relatives/ItemRelatives.js index 02bd9d8..81f4b16 100644 --- a/components/dashboard/userAccount/detailUser/relatives/ItemRelatives.js +++ b/components/dashboard/userAccount/detailUser/relatives/ItemRelatives.js @@ -13,16 +13,11 @@ function ItemRelatives({ row, idx, changeData }) { address: row.contact.address, }; - const [data, setData] = useState(contentData); - const resetData = () => setData(contentData); + const [data, setData] = useState(row); + const resetData = () => setData(row); useEffect(() => { - setData({ - name: row.name, - relation: row.relation, - phone: row.contact.phone, - address: row.contact.address, - }); + setData(row); }, [row]); return ( diff --git a/components/dashboard/userAccount/detailUser/relatives/index.js b/components/dashboard/userAccount/detailUser/relatives/index.js index bce4e25..fcddc23 100644 --- a/components/dashboard/userAccount/detailUser/relatives/index.js +++ b/components/dashboard/userAccount/detailUser/relatives/index.js @@ -9,6 +9,7 @@ function Relatives({ data, changeData, loading, updateData }) { const tableHead = ["ردیف", "نام", "نسبت", "شماره تماس", "آدرس", ""]; const centerTable = [0]; const [open, setOpen] = useState(false); + console.log(relatives); return (
diff --git a/components/dashboard/userAccount/detailUser/relatives/modal/Content.js b/components/dashboard/userAccount/detailUser/relatives/modal/Content.js index 83877f1..4a436b4 100644 --- a/components/dashboard/userAccount/detailUser/relatives/modal/Content.js +++ b/components/dashboard/userAccount/detailUser/relatives/modal/Content.js @@ -3,7 +3,18 @@ import Field from "@/app/component/Field"; function Content({ setData, data }) { const handleChange = (name, value) => - setData((prev) => ({ ...prev, [name]: value })); + name === "phone" || name === "address" + ? setData((prev) => ({ + ...prev, + contact: { + ...prev.contact, + [name]: value, + }, + })) + : setData((prev) => ({ + ...prev, + [name]: value, + })); return (
@@ -33,7 +44,7 @@ function Content({ setData, data }) { type="number" name="phone" isPlaceHolder={true} - value={Number(data?.phone.replace(/^\+/, ""))} + value={Number(data?.contact?.phone.replace(/^\+/, ""))} handleChange={handleChange} /> @@ -43,7 +54,7 @@ function Content({ setData, data }) { type="text" name="address" isPlaceHolder={true} - value={data?.address} + value={data?.contact?.address} handleChange={handleChange} /> diff --git a/components/dashboard/userAccount/detailUser/relatives/modal/index.js b/components/dashboard/userAccount/detailUser/relatives/modal/index.js index efec2d9..39346ce 100644 --- a/components/dashboard/userAccount/detailUser/relatives/modal/index.js +++ b/components/dashboard/userAccount/detailUser/relatives/modal/index.js @@ -10,27 +10,21 @@ function ModalAddRelatives({ open, setOpen, changeData, loading, updateData }) { const contentItem = { name: "", relation: "", - phone: "", - address: "", + contact: { + phone: "", + address: "", + }, }; const handleOpen = () => setOpen(true); const handleClose = () => setOpen(false); const [newItem, setNewItem] = useState(contentItem); const handleAddData = () => { - const changedKey = { - name: newItem.name, - relation: newItem.relation, - contact: { - phone: newItem.phone, - address: newItem.address, - }, - }; - - changeData("add", "relatives", null, changedKey); + changeData("add", "relatives", null, newItem); setNewItem(contentItem); handleClose(); }; + console.log(newItem); return ( <> @@ -64,8 +58,8 @@ function ModalAddRelatives({ open, setOpen, changeData, loading, updateData }) { disabled={ !newItem.name || !newItem.relation || - !newItem.phone || - !newItem.address + !newItem.contact.phone || + !newItem.contact.address } variant="contained" > diff --git a/components/layout/sidebar/Head.js b/components/layout/sidebar/Head.js index 862a8af..dcec90a 100644 --- a/components/layout/sidebar/Head.js +++ b/components/layout/sidebar/Head.js @@ -1,26 +1,21 @@ +import { getParsedUserInfo } from "@/helper"; import Image from "next/image"; function Head({ user }) { - // const userInfo = Cookies.get("userInfo"); - // const parsedInfo = userInfo && JSON.parse(userInfo); + const userInfo = getParsedUserInfo(); return (
profile

- {/* {parsedInfo?.realName} */} - user -

-

- {/* {parsedInfo?.username} */} - user + {userInfo?.realName}

diff --git a/helper/index.js b/helper/index.js index 111dd4c..a82d157 100644 --- a/helper/index.js +++ b/helper/index.js @@ -224,3 +224,195 @@ export const removeAdditionalKeysDashboard = (information) => { return usedKays; }; + +// handle TimeStamp + +function div(a, b) { + return Math.floor(a / b); +} + +function isLeapGregorian(year) { + return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; +} + +function dayOfYearToGregorian(year, dayOfYear) { + const monthDays = [ + 31, + isLeapGregorian(year) ? 29 : 28, + 31, + 30, + 31, + 30, + 31, + 31, + 30, + 31, + 30, + 31, + ]; + let month = 1; + while (dayOfYear > monthDays[month - 1]) { + dayOfYear -= monthDays[month - 1]; + month++; + } + return { month, day: dayOfYear }; +} + +function jalaliToGregorian(jy, jm, jd) { + jy = parseInt(jy); + jm = parseInt(jm); + jd = parseInt(jd); + + const breaks = [ + -61, 9, 38, 199, 426, 686, 756, 818, 1111, 1181, 1210, 1635, 2060, 2097, + 2192, 2262, 2324, 2394, 2456, 3178, + ]; + + let gy = jy + 621; + let leapJ = -14; + let jp = breaks[0]; + let jump, i; + + for (i = 1; i < breaks.length; i++) { + jump = breaks[i] - jp; + if (jy < breaks[i]) break; + leapJ += div(jump, 33) * 8 + div(jump % 33, 4); + jp = breaks[i]; + } + + let nYear = jy - jp; + leapJ += div(nYear, 33) * 8 + div((nYear % 33) + 3, 4); + if (jump % 33 === 4 && jump - nYear === 4) leapJ += 1; + + let leapG = div(gy, 4) - div((div(gy, 100) + 1) * 3, 4) - 150; + let march = 20 + leapJ - leapG; + + let gregorianYear = gy; + let gregorianMonth, gregorianDay; + + let jalaliDayOfYear = jm <= 7 ? (jm - 1) * 31 + jd : (jm - 7) * 30 + 186 + jd; + + if (jalaliDayOfYear <= march) { + gregorianYear -= 1; + const daysInPrevYear = isLeapGregorian(gregorianYear) ? 366 : 365; + const dayOfYear = daysInPrevYear - (march - jalaliDayOfYear); + const gDate = dayOfYearToGregorian(gregorianYear, dayOfYear); + gregorianMonth = gDate.month; + gregorianDay = gDate.day; + } else { + const dayOfYear = jalaliDayOfYear - march; + const gDate = dayOfYearToGregorian(gregorianYear, dayOfYear); + gregorianMonth = gDate.month; + gregorianDay = gDate.day; + } + + return { gy: gregorianYear, gm: gregorianMonth, gd: gregorianDay }; +} + +function gregorianToJalali(gy, gm, gd) { + gy = parseInt(gy); + gm = parseInt(gm); + gd = parseInt(gd); + + const breaks = [ + -61, 9, 38, 199, 426, 686, 756, 818, 1111, 1181, 1210, 1635, 2060, 2097, + 2192, 2262, 2324, 2394, 2456, 3178, + ]; + + let jy = 0; + let leapJ = -14; + let jp = breaks[0]; + let jump, i; + + for (i = 1; i < breaks.length; i++) { + jump = breaks[i] - jp; + if (gy < breaks[i]) break; + leapJ += div(jump, 33) * 8 + div(jump % 33, 4); + jp = breaks[i]; + } + + let nYear = gy - jp; + leapJ += div(nYear, 33) * 8 + div((nYear % 33) + 3, 4); + if (jump % 33 === 4 && jump - nYear === 4) leapJ += 1; + + let leapG = div(gy, 4) - div((div(gy, 100) + 1) * 3, 4) - 150; + let march = 20 + leapJ - leapG; + + let gregorianDayOfYear = dayOfYear(gy, gm, gd); + let jalaliDayOfYear, jyNew; + + if (gregorianDayOfYear > march) { + jalaliDayOfYear = gregorianDayOfYear - march; + jyNew = gy - 621; + } else { + let daysInPrevYear = isLeapGregorian(gy - 1) ? 366 : 365; + jalaliDayOfYear = gregorianDayOfYear + daysInPrevYear - march; + jyNew = gy - 622; + } + + let jmNew, jdNew; + if (jalaliDayOfYear <= 186) { + jmNew = Math.ceil(jalaliDayOfYear / 31); + jdNew = jalaliDayOfYear % 31; + if (jdNew === 0) jdNew = 31; + } else { + jalaliDayOfYear -= 186; + jmNew = Math.ceil(jalaliDayOfYear / 30) + 6; + jdNew = jalaliDayOfYear % 30; + if (jdNew === 0) jdNew = 30; + } + + return { jy: jyNew, jm: jmNew, jd: jdNew }; +} + +function dayOfYear(year, month, day) { + const monthDays = [ + 31, + isLeapGregorian(year) ? 29 : 28, + 31, + 30, + 31, + 30, + 31, + 31, + 30, + 31, + 30, + 31, + ]; + let doy = 0; + for (let i = 1; i < month; i++) { + doy += monthDays[i - 1]; + } + doy += day; + return doy; +} + +export function convertJalaliTimestamp(input, convertToTimestamp) { + if (convertToTimestamp) { + // input = { jy, jm, jd, hour?, minute?, second? } + const { jy, jm, jd, hour = 0, minute = 0, second = 0 } = input; + const { gy, gm, gd } = jalaliToGregorian(jy, jm, jd); + const date = new Date(gy, gm - 1, gd, hour, minute, second); + return Math.floor(date.getTime() / 1000); + } else { + const date = new Date(input * 1000); + const gy = date.getFullYear(); + const gm = date.getMonth() + 1; + const gd = date.getDate(); + const hour = date.getHours(); + const minute = date.getMinutes(); + const second = date.getSeconds(); + const { jy, jm, jd } = gregorianToJalali(gy, gm, gd); + return { jy, jm, jd, hour, minute, second }; + } +} + +const timestamp = convertJalaliTimestamp( + { jy: 1404, jm: 4, jd: 3, hour: 22, minute: 36, second: 10 }, + true +); +console.log(timestamp); + +const jalaliDate = convertJalaliTimestamp(1750791970, false); +console.log(jalaliDate); diff --git a/package-lock.json b/package-lock.json index 33601cb..c211890 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,7 @@ "dayjs": "^1.11.13", "html2canvas": "^1.4.1", "i": "^0.3.7", + "jalaali-js": "^1.2.8", "jalaali-react-date-picker": "^1.0.18", "jalali-moment": "^3.3.11", "js-cookie": "^3.0.5", @@ -12693,9 +12694,9 @@ } }, "node_modules/jalaali-js": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/jalaali-js/-/jalaali-js-1.2.7.tgz", - "integrity": "sha512-gE+YHWSbygYAoJa+Xg8LWxGILqFOxZSBQQw39ghel01fVFUxV7bjL0x1JFsHcLQ3uPjvn81HQMa+kxwyPWnxGQ==", + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/jalaali-js/-/jalaali-js-1.2.8.tgz", + "integrity": "sha512-Jl/EwY84JwjW2wsWqeU4pNd22VNQ7EkjI36bDuLw31wH98WQW4fPjD0+mG7cdCK+Y8D6s9R3zLiQ3LaKu6bD8A==", "license": "MIT" }, "node_modules/jalaali-react-date-picker": { diff --git a/package.json b/package.json index 531dca0..0a9f51b 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "dayjs": "^1.11.13", "html2canvas": "^1.4.1", "i": "^0.3.7", + "jalaali-js": "^1.2.8", "jalaali-react-date-picker": "^1.0.18", "jalali-moment": "^3.3.11", "js-cookie": "^3.0.5", diff --git a/public/assets/icons/double-right.svg b/public/assets/icons/double-right.svg new file mode 100644 index 0000000..a4d4de3 --- /dev/null +++ b/public/assets/icons/double-right.svg @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file