From 5b90f7dfad3e10044611334b39ab52dd5163be45 Mon Sep 17 00:00:00 2001 From: hamedhosseini Date: Sun, 29 Jun 2025 19:50:35 +0330 Subject: [PATCH 1/8] change functionality req from ssr to csr set dockerfile reset dockerfile fix dockerfile fix dockerfile use node 22 fix dockerfile fix dockerfile --- Dockerfile | 4 ++-- .../dashboard/userAccount/detailUser/index.js | 6 ++---- .../detailUser/information/Content.js | 2 -- .../detailUser/information/DateBirthday.js | 2 +- .../userAccount/detailUser/information/Form.js | 18 ++++++++---------- .../detailUser/information/component/Field.js | 2 +- .../detailUser/information/index.js | 16 +++++++++++++--- helper/index.js | 7 +++++++ 8 files changed, 34 insertions(+), 23 deletions(-) diff --git a/Dockerfile b/Dockerfile index e003570..37c845a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # Dockerfile for Next.js 14 - Optimized for Production # Use the official Node.js image with Alpine Linux for a smaller footprint -FROM node:20-alpine AS base +FROM node:22-alpine AS base # Set the working directory in the container WORKDIR /app @@ -19,7 +19,7 @@ COPY . . RUN npm run build || yarn build # Stage 2: Production image - smaller and leaner -FROM node:20-alpine AS runner +FROM node:22-alpine AS runner # Set the working directory WORKDIR /app diff --git a/components/dashboard/userAccount/detailUser/index.js b/components/dashboard/userAccount/detailUser/index.js index 90edcde..1338522 100644 --- a/components/dashboard/userAccount/detailUser/index.js +++ b/components/dashboard/userAccount/detailUser/index.js @@ -13,6 +13,7 @@ import FamilyHistory from "./familyHistory"; import Relatives from "./relatives"; import { dieses } from "./information/dieses"; import Cookies from "js-cookie"; +import { getParsedUserInfo } from "@/helper"; function DetailUser({ user, @@ -45,9 +46,7 @@ function DetailUser({ }; useEffect(() => { - const user = Cookies.get("userInfo"); - const parsedUserInfo = user && JSON.parse(user); - console.log(parsedUserInfo); + const parsedUserInfo = getParsedUserInfo(); if (parsedUserInfo) { request @@ -63,7 +62,6 @@ function DetailUser({ // handle Error } }, []); - console.log(information); if (!dataUser) { initialData.other = [ diff --git a/components/dashboard/userAccount/detailUser/information/Content.js b/components/dashboard/userAccount/detailUser/information/Content.js index a46177c..7d92ebe 100644 --- a/components/dashboard/userAccount/detailUser/information/Content.js +++ b/components/dashboard/userAccount/detailUser/information/Content.js @@ -1,6 +1,4 @@ function Content({ isConfirmed, children, title, error }) { - console.log(error); - return (
diff --git a/components/dashboard/userAccount/detailUser/information/DateBirthday.js b/components/dashboard/userAccount/detailUser/information/DateBirthday.js index 6dbab1d..750b548 100644 --- a/components/dashboard/userAccount/detailUser/information/DateBirthday.js +++ b/components/dashboard/userAccount/detailUser/information/DateBirthday.js @@ -60,7 +60,7 @@ function DateBirthday({ data, changeData, error }) { { - changeData(convertToJalali(e._d), "value", "birthday"); + changeData(convertToJalali(e._d), "birthday"); handleClose(); }} /> diff --git a/components/dashboard/userAccount/detailUser/information/Form.js b/components/dashboard/userAccount/detailUser/information/Form.js index efb01a7..5a8f04c 100644 --- a/components/dashboard/userAccount/detailUser/information/Form.js +++ b/components/dashboard/userAccount/detailUser/information/Form.js @@ -1,3 +1,4 @@ +import { getParsedUserInfo } from "@/helper"; import Content from "./Content"; import DateBirthday from "./DateBirthday"; import AutoSelector from "./component/AutoSelector"; @@ -22,6 +23,8 @@ function Form({ const findVal = (list, name) => data && list && list.length && list.find((g) => g.id === data[name]); console.log(errors); + const parsedUserInfo = getParsedUserInfo(); + console.log(parsedUserInfo); return (
@@ -72,7 +75,7 @@ function Form({ - changeData(data === "زن" ? "female" : "male", "value", name) + changeData(data === "زن" ? "female" : "male", name) } value={findVal(gender, "gender")} label="جنسیت" @@ -101,7 +104,7 @@ function Form({ { - changeData([Number(val.id)], "value", name); + changeData([Number(val.id)], name); }} // value={findVal(insurance, "basic_insurance", true)?.name} value={insurance?.find( @@ -133,11 +136,7 @@ function Form({ - changeData( - blood_group.find((g) => g.label === value).id, - "value", - name - ) + changeData(blood_group.find((g) => g.label === value).id, name) } value={findVal(blood_group, "blood_type")} label="گروه خونی" @@ -149,7 +148,7 @@ function Form({ - changeData(value === "متاهل" ? "married" : "single", "value", name) + changeData(value === "متاهل" ? "married" : "single", name) } value={findVal(marital_status, "marital_status")} label="وضعیت تاهل" @@ -173,7 +172,6 @@ function Form({ updateData={(name, value) => changeData( education.find((g) => g.label === value).id, - "value", name ) } @@ -187,7 +185,7 @@ function Form({ - changeData(value === "آزاد" ? "azad" : "dolati", "value", name) + changeData(value === "آزاد" ? "azad" : "dolati", name) } value={findVal(job, "job")} label="شغل" diff --git a/components/dashboard/userAccount/detailUser/information/component/Field.js b/components/dashboard/userAccount/detailUser/information/component/Field.js index 7b7dad7..9e93fae 100644 --- a/components/dashboard/userAccount/detailUser/information/component/Field.js +++ b/components/dashboard/userAccount/detailUser/information/component/Field.js @@ -29,7 +29,7 @@ function Field({ isTransparent ? "!bg-transparent lg:!bg-[#FFF]" : "!bg-[#FFF]" }`} onChange={(e) => { - changeData(e.target.value, "value", name); + changeData(e.target.value, name); }} sx={{ // border: "1px solid red !important", diff --git a/components/dashboard/userAccount/detailUser/information/index.js b/components/dashboard/userAccount/detailUser/information/index.js index 2cadc8b..e070ef1 100644 --- a/components/dashboard/userAccount/detailUser/information/index.js +++ b/components/dashboard/userAccount/detailUser/information/index.js @@ -20,7 +20,7 @@ function Information({ const [disable, setDisable] = useState(true); const [insurance, setInsurance] = useState(); const [loading, setLoading] = useState(false); - const [errors, setErrors] = useState(); + const [errors, setErrors] = useState({}); useEffect(() => { request.getInsuranceType().then((res) => { @@ -31,12 +31,19 @@ function Information({ // .catch((err) => {}); }, []); - const changeData = (value, type, name) => { + const changeData = (value, name) => { setInformation({ ...information, [name]: value, }); + if (errors && errors[name]) { + setErrors({ + ...errors, + [name]: false, + }); + } }; + console.log(information); const validationInfo = () => {}; @@ -44,9 +51,11 @@ function Information({ setLoading(true); console.log(prevInfo); console.log(prevInfo ? true : false); + console.log(information); + if (!validationInfo()) request[prevInfo ? "patchUserProfile" : "postUserProfile"]( - data, + information, prevInfo ? prevInfo.uuid : Cookies.get("uuid") ) .then((res) => { @@ -83,6 +92,7 @@ function Information({ variant="contained" onClick={sendReq} loading={loading} + disabled={Object.values(errors).find((error) => error)} 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] diff --git a/helper/index.js b/helper/index.js index 50015e7..6d9fe58 100644 --- a/helper/index.js +++ b/helper/index.js @@ -1,6 +1,7 @@ import moment from "jalali-moment"; import { toast } from "react-toastify"; import specialties from "@/data/specialties.json"; +import Cookies from "js-cookie"; export const numberToArStyle = (num) => num?.toLocaleString("ar-AE") || ""; @@ -194,3 +195,9 @@ export function hasDataChanged(previousData, newData) { const newDataString = JSON.stringify(newData, Object.keys(newData).sort()); return oldDataString !== newDataString; } + +export const getParsedUserInfo = () => { + const user = Cookies.get("userInfo"); + const parsedUserInfo = user && JSON.parse(user); + return parsedUserInfo; +}; From 08bfb3ea83d16cb1725febf514394b64015bbe48 Mon Sep 17 00:00:00 2001 From: hamedhosseini Date: Sun, 29 Jun 2025 20:03:50 +0330 Subject: [PATCH 2/8] fix dockerfile fix dockerfile fix dockerfile From cc581e45c6ff3b15567b318a578bb9cc57dd7cca Mon Sep 17 00:00:00 2001 From: hamedhosseini Date: Mon, 30 Jun 2025 11:10:53 +0330 Subject: [PATCH 3/8] set nixpack --- nixpacks.toml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/nixpacks.toml b/nixpacks.toml index dc109f0..e8cddd6 100644 --- a/nixpacks.toml +++ b/nixpacks.toml @@ -1,5 +1,20 @@ [phases.setup] nixPkgs = ["nodejs_22"] +[phases.install] +cmds = ["npm install --production --frozen-lockfile"] + +[phases.build] +cmds = ["npm run build"] + [start] -cmd = "pnpm run start" +cmd = "node server.js" + +[variables] +NODE_ENV = "production" +NEXT_TELEMETRY_DISABLED = "1" + +# These environment variables will need to be set in your deployment platform +# NEXT_PUBLIC_API_URL - Set in deployment platform +# NEXT_PUBLIC_CLIENT_ID - Set in deployment platform +# NEXT_PUBLIC_CLIENT_SECRET - Set in deployment platform \ No newline at end of file From c598360189403dba8f33de5258f5dcd96fa71afc Mon Sep 17 00:00:00 2001 From: hamedhosseini Date: Mon, 30 Jun 2025 11:54:06 +0330 Subject: [PATCH 4/8] fix dockerfile --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 37c845a..5b94891 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,13 +10,13 @@ WORKDIR /app COPY package*.json ./ # Install dependencies - leveraging Docker cache -RUN npm install --production --frozen-lockfile || yarn install --production --frozen-lockfile +RUN npm i --force # Copy the rest of the application code COPY . . # Build the Next.js application -RUN npm run build || yarn build +RUN npm run build # Stage 2: Production image - smaller and leaner FROM node:22-alpine AS runner @@ -26,7 +26,7 @@ WORKDIR /app # Set environment variables ENV NODE_ENV production -ENV NEXT_TELEMETRY_DISABLED 1 # Opt-out of Next.js telemetry +ENV NEXT_TELEMETRY_DISABLED 1 # Add a non-root user for security RUN addgroup -g 1001 -S nodejs From bb983bd1ab18ee88563fd4aa398ef747e16fd3b9 Mon Sep 17 00:00:00 2001 From: hamedhosseini Date: Mon, 30 Jun 2025 18:04:57 +0330 Subject: [PATCH 5/8] set port --- docker-compose.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 2a8e54a..65ea15d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,12 +12,15 @@ services: - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} - NEXT_PUBLIC_CLIENT_ID=${NEXT_PUBLIC_CLIENT_ID} - NEXT_PUBLIC_CLIENT_SECRET=${NEXT_PUBLIC_CLIENT_SECRET} + - PORT restart: unless-stopped container_name: nobat724-frontend ports: - - "3001:3000" + - "${PORT}:3000" environment: - NODE_ENV=production - NEXT_TELEMETRY_DISABLED=1 - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} - NEXT_PUBLIC_CLIENT_ID=${NEXT_PUBLIC_CLIENT_ID} + - NEXT_PUBLIC_CLIENT_SECRET=${NEXT_PUBLIC_CLIENT_SECRET} + - PORT={PORT} \ No newline at end of file From 36f3658801a6fb2f64e4b18079dedaf7ed4484ba Mon Sep 17 00:00:00 2001 From: hamedhosseini Date: Mon, 30 Jun 2025 18:11:11 +0330 Subject: [PATCH 6/8] set port --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 65ea15d..88c799c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,7 @@ services: - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} - NEXT_PUBLIC_CLIENT_ID=${NEXT_PUBLIC_CLIENT_ID} - NEXT_PUBLIC_CLIENT_SECRET=${NEXT_PUBLIC_CLIENT_SECRET} - - PORT + - PORT=${PORT} restart: unless-stopped container_name: nobat724-frontend ports: From 915e50b6a476d64beb8c35e9b7080d7626c399ef Mon Sep 17 00:00:00 2001 From: hamedhosseini Date: Mon, 30 Jun 2025 18:27:33 +0330 Subject: [PATCH 7/8] set port for build --- docker-compose.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 88c799c..fd8ec69 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,6 @@ services: - NEXT_PUBLIC_CLIENT_SECRET=${NEXT_PUBLIC_CLIENT_SECRET} - PORT=${PORT} restart: unless-stopped - container_name: nobat724-frontend ports: - "${PORT}:3000" environment: @@ -23,4 +22,4 @@ services: - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} - NEXT_PUBLIC_CLIENT_ID=${NEXT_PUBLIC_CLIENT_ID} - NEXT_PUBLIC_CLIENT_SECRET=${NEXT_PUBLIC_CLIENT_SECRET} - - PORT={PORT} \ No newline at end of file + - PORT=${PORT} \ No newline at end of file From 7a51b00732a498c88e1e1693890646b2224e9ddd Mon Sep 17 00:00:00 2001 From: hamedhosseini Date: Mon, 30 Jun 2025 18:48:30 +0330 Subject: [PATCH 8/8] set port for build --- docker-compose.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index fd8ec69..d45d186 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,14 +12,13 @@ services: - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} - NEXT_PUBLIC_CLIENT_ID=${NEXT_PUBLIC_CLIENT_ID} - NEXT_PUBLIC_CLIENT_SECRET=${NEXT_PUBLIC_CLIENT_SECRET} - - PORT=${PORT} restart: unless-stopped ports: - - "${PORT}:3000" + - "${APP_PORT}:3000" environment: - NODE_ENV=production - NEXT_TELEMETRY_DISABLED=1 - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} - NEXT_PUBLIC_CLIENT_ID=${NEXT_PUBLIC_CLIENT_ID} - NEXT_PUBLIC_CLIENT_SECRET=${NEXT_PUBLIC_CLIENT_SECRET} - - PORT=${PORT} \ No newline at end of file + - APP_PORT=${APP_PORT} \ No newline at end of file