From 13adfa55df59d458e3bc16571c8524e5062a5a69 Mon Sep 17 00:00:00 2001 From: Hossein Rahmani Date: Fri, 5 Jan 2024 14:26:34 +0330 Subject: [PATCH] bugs fixed + docker added --- .dockerignore | 7 + .github/workflows/build.yml | 49 ++++ Dockerfile | 59 ++++ .../AdminDashboard/KeysManagement/page.tsx | 8 - .../AdminDashboard/UserManagement/page.tsx | 8 - .../(Admin)/AdminDashboard/layout.tsx | 16 -- app/UserPanel/(Admin)/AdminDashboard/page.tsx | 8 - .../(Citizen)/CitizenDashboard/layout.tsx | 14 - .../(Citizen)/CitizenDashboard/page.tsx | 7 - .../Complaints/[id]/page.tsx | 18 -- .../ControllerDashboard/Complaints/page.tsx | 8 - .../ControllerDashboard/Reports/page.tsx | 8 - .../ControllerDashboard/layout.tsx | 21 -- .../(Controller)/ControllerDashboard/page.tsx | 8 - app/UserPanel/page.tsx | 7 - app/components/Landing.tsx | 2 +- components/AdminDashboard.tsx | 35 --- components/AdminKeysManagement.tsx | 257 ------------------ components/AdminUserManagement.tsx | 134 --------- components/CallUs.tsx | 8 +- components/CitizenLogin.tsx | 2 +- components/ComplainsDetails.tsx | 5 +- components/ControllerDashboard.tsx | 73 ----- components/Footer.tsx | 20 +- components/HorizontalChart.tsx | 68 ----- components/InspectorOperations.tsx | 17 +- components/LineChart.tsx | 64 ----- components/Navbar.tsx | 4 +- components/NavbarSm.tsx | 2 +- components/PieChart.tsx | 37 --- components/ProfileDropDown.tsx | 6 +- components/ReportsController.tsx | 106 -------- components/RequestResult.tsx | 23 +- components/RequestStep2.tsx | 2 +- components/SubmitRequest.tsx | 109 ++++---- components/TableAdmin.tsx | 63 ----- components/TableController.tsx | 11 +- components/Verify.tsx | 1 - components/VerticalChart.tsx | 60 ---- constants/index.tsx | 46 +++- docker-compose.yml | 8 + utils/adminApi.ts | 34 --- utils/authenticateApi.ts | 2 +- utils/citizenApi.ts | 2 +- 44 files changed, 271 insertions(+), 1176 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/build.yml create mode 100644 Dockerfile delete mode 100644 app/UserPanel/(Admin)/AdminDashboard/KeysManagement/page.tsx delete mode 100644 app/UserPanel/(Admin)/AdminDashboard/UserManagement/page.tsx delete mode 100644 app/UserPanel/(Admin)/AdminDashboard/layout.tsx delete mode 100644 app/UserPanel/(Admin)/AdminDashboard/page.tsx delete mode 100644 app/UserPanel/(Citizen)/CitizenDashboard/layout.tsx delete mode 100644 app/UserPanel/(Citizen)/CitizenDashboard/page.tsx delete mode 100644 app/UserPanel/(Controller)/ControllerDashboard/Complaints/[id]/page.tsx delete mode 100644 app/UserPanel/(Controller)/ControllerDashboard/Complaints/page.tsx delete mode 100644 app/UserPanel/(Controller)/ControllerDashboard/Reports/page.tsx delete mode 100644 app/UserPanel/(Controller)/ControllerDashboard/layout.tsx delete mode 100644 app/UserPanel/(Controller)/ControllerDashboard/page.tsx delete mode 100644 app/UserPanel/page.tsx delete mode 100644 components/AdminDashboard.tsx delete mode 100644 components/AdminKeysManagement.tsx delete mode 100644 components/AdminUserManagement.tsx delete mode 100644 components/ControllerDashboard.tsx delete mode 100644 components/HorizontalChart.tsx delete mode 100644 components/LineChart.tsx delete mode 100644 components/PieChart.tsx delete mode 100644 components/ReportsController.tsx delete mode 100644 components/TableAdmin.tsx delete mode 100644 components/VerticalChart.tsx create mode 100644 docker-compose.yml delete mode 100644 utils/adminApi.ts diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c550055 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +Dockerfile +.dockerignore +node_modules +npm-debug.log +README.md +.next +.git diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..cb73d10 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,49 @@ +name: build + +on: + push: + tags: + - "v*.*.*" + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + # list of Docker images to use as base name for tags + images: | + ${{ secrets.DOCKER_REGISTRY }}oyoon + + # generate Docker tags based on the following events/attributes + tags: | + type=ref,event=branch + type=semver,pattern={{major}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{version}} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + registry: ${{ secrets.DOCKER_REGISTRY }} + username: ${{ secrets.DOCKER_REGISTRY_USERNAME }} + password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + push: true + context: "{{defaultContext}}" + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9b6a0e9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,59 @@ +FROM node:18-alpine AS base + +# Install dependencies only when needed +FROM base AS deps +# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. +RUN apk add --no-cache libc6-compat +WORKDIR /app + +# Install dependencies based on the preferred package manager +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ +RUN \ + if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ + elif [ -f package-lock.json ]; then npm ci; \ + elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \ + else echo "Lockfile not found." && exit 1; \ + fi + + +# Rebuild the source code only when needed +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +# Next.js collects completely anonymous telemetry data about general usage. +# Learn more here: https://nextjs.org/telemetry +# Uncomment the following line in case you want to disable telemetry during the build. +# ENV NEXT_TELEMETRY_DISABLED 1 + +RUN yarn build + +# If using npm comment out above and use below instead +# RUN npm run build + +# Production image, copy all the files and run next +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV production +# Uncomment the following line in case you want to disable telemetry during runtime. +# ENV NEXT_TELEMETRY_DISABLED 1 + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public + +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs + +EXPOSE 6679 + +ENV PORT 6679 + +CMD ["node", "server.js"] \ No newline at end of file diff --git a/app/UserPanel/(Admin)/AdminDashboard/KeysManagement/page.tsx b/app/UserPanel/(Admin)/AdminDashboard/KeysManagement/page.tsx deleted file mode 100644 index 24aea02..0000000 --- a/app/UserPanel/(Admin)/AdminDashboard/KeysManagement/page.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import AdminKeysManagement from '@/components/AdminKeysManagement' -import React from 'react' - -export default function page() { - return ( - - ) -} diff --git a/app/UserPanel/(Admin)/AdminDashboard/UserManagement/page.tsx b/app/UserPanel/(Admin)/AdminDashboard/UserManagement/page.tsx deleted file mode 100644 index ec7fdbb..0000000 --- a/app/UserPanel/(Admin)/AdminDashboard/UserManagement/page.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import AdminUserManagement from '@/components/AdminUserManagement' -import React from 'react' - -export default function page() { - return ( - - ) -} diff --git a/app/UserPanel/(Admin)/AdminDashboard/layout.tsx b/app/UserPanel/(Admin)/AdminDashboard/layout.tsx deleted file mode 100644 index 1c0558a..0000000 --- a/app/UserPanel/(Admin)/AdminDashboard/layout.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import NavbarPanel from "@/components/NavbarPanel"; - -export default function RootLayout({ - children, - }: { - children: React.ReactNode; - }) { - return ( - <> - - - {children} - - ) - -} \ No newline at end of file diff --git a/app/UserPanel/(Admin)/AdminDashboard/page.tsx b/app/UserPanel/(Admin)/AdminDashboard/page.tsx deleted file mode 100644 index 4119248..0000000 --- a/app/UserPanel/(Admin)/AdminDashboard/page.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import AdminDashboard from "@/components/AdminDashboard"; -import React from "react"; - -export default function page() { - return ( - - ); -} diff --git a/app/UserPanel/(Citizen)/CitizenDashboard/layout.tsx b/app/UserPanel/(Citizen)/CitizenDashboard/layout.tsx deleted file mode 100644 index 1c938e8..0000000 --- a/app/UserPanel/(Citizen)/CitizenDashboard/layout.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import NavbarPanel from "@/components/NavbarPanel"; - -export default function RootLayout({ - children, - }: { - children: React.ReactNode; - }) { - return ( - <> - {children} - - ) - -} \ No newline at end of file diff --git a/app/UserPanel/(Citizen)/CitizenDashboard/page.tsx b/app/UserPanel/(Citizen)/CitizenDashboard/page.tsx deleted file mode 100644 index cb2be10..0000000 --- a/app/UserPanel/(Citizen)/CitizenDashboard/page.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from 'react' - -export default function page() { - return ( -
page
- ) -} diff --git a/app/UserPanel/(Controller)/ControllerDashboard/Complaints/[id]/page.tsx b/app/UserPanel/(Controller)/ControllerDashboard/Complaints/[id]/page.tsx deleted file mode 100644 index 1843f83..0000000 --- a/app/UserPanel/(Controller)/ControllerDashboard/Complaints/[id]/page.tsx +++ /dev/null @@ -1,18 +0,0 @@ -import ComplainsDetails from "@/components/ComplainsDetails"; -import React from "react"; - -export default function page({ params }: { params: any }) { - const id = params.id; - { - console.log(params); - } - { - console.log(id); - } - - return ( -
- ; -
- ); -} diff --git a/app/UserPanel/(Controller)/ControllerDashboard/Complaints/page.tsx b/app/UserPanel/(Controller)/ControllerDashboard/Complaints/page.tsx deleted file mode 100644 index 441aec1..0000000 --- a/app/UserPanel/(Controller)/ControllerDashboard/Complaints/page.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import TabController from '@/components/TabController' -import React from 'react' - -export default function page() { - return ( - - ) -} diff --git a/app/UserPanel/(Controller)/ControllerDashboard/Reports/page.tsx b/app/UserPanel/(Controller)/ControllerDashboard/Reports/page.tsx deleted file mode 100644 index 48557be..0000000 --- a/app/UserPanel/(Controller)/ControllerDashboard/Reports/page.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import ReportsController from '@/components/ReportsController' -import React from 'react' - -export default function page() { - return ( - - ) -} diff --git a/app/UserPanel/(Controller)/ControllerDashboard/layout.tsx b/app/UserPanel/(Controller)/ControllerDashboard/layout.tsx deleted file mode 100644 index 26a0c2b..0000000 --- a/app/UserPanel/(Controller)/ControllerDashboard/layout.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import NavbarPanel from "@/components/NavbarPanel"; -import { cookies } from "next/headers"; -import { redirect } from "next/navigation"; - -export default function RootLayout({ - children, -}: { - children: React.ReactNode; -}) { - // const cookieStore = cookies(); - // const token = cookieStore.get("Sootzani-Token"); - // if (!token.value) { - // return redirect("/"); - // } - return ( - <> - - {children} - - ); -} diff --git a/app/UserPanel/(Controller)/ControllerDashboard/page.tsx b/app/UserPanel/(Controller)/ControllerDashboard/page.tsx deleted file mode 100644 index ff4fa83..0000000 --- a/app/UserPanel/(Controller)/ControllerDashboard/page.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import ControllerDashboard from "@/components/ControllerDashboard"; -import React from "react"; - -export default function page() { - return ( - - ); -} diff --git a/app/UserPanel/page.tsx b/app/UserPanel/page.tsx deleted file mode 100644 index 346db35..0000000 --- a/app/UserPanel/page.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from 'react' - -export default function page() { - return ( -
Userpage
- ) -} diff --git a/app/components/Landing.tsx b/app/components/Landing.tsx index ac46449..3d35800 100644 --- a/app/components/Landing.tsx +++ b/app/components/Landing.tsx @@ -136,7 +136,7 @@ export default function Landing() { 24 آذر ماه 1402

- شروع به کار سامانه سوت زنی + شروع به کار سامانه عیون

این سامانه با هدف نظارت بر عملکرد پرستل و نهادهای مرتبط با امور diff --git a/components/AdminDashboard.tsx b/components/AdminDashboard.tsx deleted file mode 100644 index 066e55e..0000000 --- a/components/AdminDashboard.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import React from "react"; -import BoxDashboard from "./BoxDashboard"; -import LineChart from "./LineChart"; -import { HorizontalChart } from "./HorizontalChart"; -import { VerticalChart } from "./VerticalChart"; -import { PieChart } from "./PieChart"; - -export default function AdminDashboard() { - return ( -

- -
- -
- - - - - - -
- -
-
- -
-
-
- -
-
-
-
- ); -} diff --git a/components/AdminKeysManagement.tsx b/components/AdminKeysManagement.tsx deleted file mode 100644 index 972cd7a..0000000 --- a/components/AdminKeysManagement.tsx +++ /dev/null @@ -1,257 +0,0 @@ -"use client"; - -import React, { useState } from "react"; -import { useQuery } from "@tanstack/react-query"; -import { GenerateKeyPair, GetKeys } from "@/utils/adminApi"; - -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, - AlertDialogTrigger, -} from "@/components/ui/alert-dialog"; -import { Button } from "@/components/ui/button"; -import { ThreeDots } from "react-loader-spinner"; - -import { - Form, - FormControl, - FormDescription, - FormField, - FormItem, - FormLabel, - FormMessage, -} from "@/components/ui/form"; -import { Input } from "@/components/ui/input"; - - -// const FormSchema = z.object({ -// title: z.string().min(2, { -// message: "trackingNumber must be at least 2 characters.", -// }), -// password: z.string().min(4, { -// message: "Password must be at least 4 characters.", -// }), -// }); - -export default function AdminKeysManagement() { - // List Keys - const { - data: data1, - error: Error1, - isLoading: isListLoading, - refetch: refetch1, - } = useQuery({ - queryKey: ["KeysList"], - queryFn: () => GetKeys(), - // refetchOnWindowFocus: false, - }); - console.log(data1); - - // GenerateKeyPair - const { - data: data2, - error: Error2, - isLoading: isNewKeyLoading, - refetch: refetch2, - } = useQuery({ - queryKey: ["GenerateKey"], - queryFn: () => GenerateKeyPair(), - enabled: false, // Disable automatic fetching - }); - const handleClick = () => { - refetch2(); - console.log(data2); - // Manually trigger the query when the button is clicked - }; - - // } - return ( -
-
- {/* 1 */} - - - - - - - اطلاعات کلید جدید - - {isNewKeyLoading ? ( -
- -
- ) : ( -
-

- کلید عمومی : -

-

- {data2?.publicKey} -

- -

- کلید خصوصی : -

-

- {data2?.privateKey} -

-
- )} -
-
- - بستن - {/* Continue */} - -
-
- - {/* 1 */} - - - - - - - افزودن کلید جدید - - {isNewKeyLoading ? ( -
- -
- ) : ( - <> - //
- // - //
- // ( - // - // - // کد پیگیری - // - // - // - // - // - // - // )} - // /> - - // ( - // - // - // رمز عبور - // - // - // - // - // - // - // )} - // /> - //
- - //
- // - //
- //
- // - )} -
-
- - بستن - {/* Continue */} - -
-
- -
- لیست کلیدها -
- {/* 2 */} -
- {data1?.map((item: any) => { - return ( -
-

- عنوان کلید : - {item.title} -

-

- آی دی بازرس : - - {item.inspectorId} - -

-
- ); - })} -
-
-
- ); -} diff --git a/components/AdminUserManagement.tsx b/components/AdminUserManagement.tsx deleted file mode 100644 index 827cd7d..0000000 --- a/components/AdminUserManagement.tsx +++ /dev/null @@ -1,134 +0,0 @@ -"use client"; -import React from "react"; -import Search from "./Search"; -import { MdOutlineManageSearch } from "react-icons/md"; -import { IoIosArrowDown } from "react-icons/io"; -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuGroup, - DropdownMenuItem, - DropdownMenuLabel, - DropdownMenuPortal, - DropdownMenuSeparator, - DropdownMenuShortcut, - DropdownMenuSub, - DropdownMenuSubContent, - DropdownMenuSubTrigger, - DropdownMenuTrigger, -} from "@/components/ui/dropdown-menu"; - -import { Button } from "./ui/button"; -import { AdminCardItems } from "@/constants"; -import TableAdmin from "./TableAdmin"; - -export default function AdminUserManagement() { - return ( -
-
-
- {/* 1 */} -
-
- مدیریت کاربران -
- -
-
- -
- -
- - - - - - - - My Account - - - - Profile - ⇧P - - - Billing - ⇧B - - - - - - - - - - - My Account - - - - Profile - ⇧P - - - Billing - ⇧B - - - - - - - -
-
-
- - {/* 2 */} -
- {AdminCardItems.map((item) => { - return ( -
-

- {item.name} -

-

- {item.count} -

-
- ); - })} -
- - {/* 3 */} -
-
- لیست کاربران -
- - -
-
-
- -
- ); -} diff --git a/components/CallUs.tsx b/components/CallUs.tsx index 8975c75..e585e97 100644 --- a/components/CallUs.tsx +++ b/components/CallUs.tsx @@ -1,12 +1,14 @@ "use client"; import Image from "next/image"; import React from "react"; -import mapImg from "../public/img/map.png"; import { callUsItems } from "@/constants"; import { cn } from "@/lib/utils"; -import Map from "./Map"; - +const Map = dynamic(() => import("./Map"), { + ssr: false, +}); +import dynamic from "next/dynamic"; + export default function CallUs(props: any) { const { position, zoom } = props; return ( diff --git a/components/CitizenLogin.tsx b/components/CitizenLogin.tsx index b2371b3..38dbddd 100644 --- a/components/CitizenLogin.tsx +++ b/components/CitizenLogin.tsx @@ -27,7 +27,6 @@ import { useRouter } from "next/navigation"; import { Oval, ThreeDots } from "react-loader-spinner"; import useData from "@/store/useData"; import { getCookie } from "cookies-next"; -import { isAuthorized } from "@/hooks/useAuthentication"; const FormSchema = z.object({ phoneNumber: z.string().min(1, { message: "لطفا شماره موبایل خود را وارد نمایید.", @@ -75,6 +74,7 @@ export default function CitizenLogin() { value: data.captcha, }, }; + refetch() loginMutation.mutate(payload); saveData({ phoneNumber: data.phoneNumber, diff --git a/components/ComplainsDetails.tsx b/components/ComplainsDetails.tsx index b3b1077..82ebfc8 100644 --- a/components/ComplainsDetails.tsx +++ b/components/ComplainsDetails.tsx @@ -5,7 +5,6 @@ import blueIcon from "../public/img/bluepoint.svg"; import Image from "next/image"; import { ComplainDetailsItems } from "@/constants"; import { useMutation } from "@tanstack/react-query"; -import { OperateByInspector, getComplaint } from "@/utils/inspectorApi"; import useData from "@/store/useData"; import { convertDate } from "@/lib/utils"; import { Badge } from "./ui/badge"; @@ -124,7 +123,9 @@ export default function ComplainsDetails({

دستگاه مربوطه:{" "} - {/* {data.title} */} + {data?.complaintOrganization + ? data?.complaintOrganization.title + : "-"}

diff --git a/components/ControllerDashboard.tsx b/components/ControllerDashboard.tsx deleted file mode 100644 index 103628d..0000000 --- a/components/ControllerDashboard.tsx +++ /dev/null @@ -1,73 +0,0 @@ -"use client"; -import React from "react"; -import BoxDashboard from "./BoxDashboard"; -import LineChart from "./LineChart"; -import { HorizontalChart } from "./HorizontalChart"; -import { getComplaintsList } from "@/utils/inspectorApi"; -import { useQuery } from "@tanstack/react-query"; -import useDecrypt from "@/hooks/useDecrypt"; - -export default function ControllerDashboard() { - const { data, isLoading, refetch } = useQuery({ - queryKey: ["ComplaintsList"], - queryFn: () => getComplaintsList(), - refetchOnWindowFocus: false, - }); - console.log(data); - const [decryptedMessage, errorMessage] = useDecrypt( - "gJoT9AqK7wk1MZFSD04yXXfF36fzsOL+RYtJfySrEnQeJ7VoaL7pmOU6nB3+0+PQcaxIi3hf1AHjzIB0Cn5oHgKROeoI4XslhAezZk23QhtIU4HUF1wpeOJfA+4hWyRfbh4fI9774sa/KL47VaBbrNM/rvBxk6hjlKx5mTb3hqM=" - ); - console.log(decryptedMessage); - if (data) { - } - console.log(errorMessage); - if (data) { - } - return ( -

- {/* Lg Show */} -
-
- - -
- -
- -
-
- -
-
- - - -
-
- -
-
- - {/* max Lg show */} -
-
- - - - - -
- -
-
- -
-
-
- -
-
-
-
- ); -} diff --git a/components/Footer.tsx b/components/Footer.tsx index 722ae5f..73276c6 100644 --- a/components/Footer.tsx +++ b/components/Footer.tsx @@ -11,20 +11,20 @@ export default function Footer() { //