From aa78a28b5df44b433d5ac7af116515f90bcfccf3 Mon Sep 17 00:00:00 2001 From: YasamanKahdooei Date: Sat, 8 Jun 2024 15:31:19 +0330 Subject: [PATCH] Added part of RequestProcess --- components/Requests/RequestCard.tsx | 5 +- components/Requests/RequestComment.tsx | 3 +- components/Requests/RequestComments.tsx | 4 +- components/Requests/RequestProcess.tsx | 139 +++++++++++++++++++++++ components/Requests/RequestViolation.tsx | 8 -- lib/utils.ts | 12 +- package-lock.json | 98 ++++++++++++++++ package.json | 2 + tailwind.config.ts | 5 +- utils/CitizenReport.ts | 7 ++ 10 files changed, 267 insertions(+), 16 deletions(-) create mode 100644 components/Requests/RequestProcess.tsx delete mode 100644 components/Requests/RequestViolation.tsx diff --git a/components/Requests/RequestCard.tsx b/components/Requests/RequestCard.tsx index ba936ab..f17ce69 100644 --- a/components/Requests/RequestCard.tsx +++ b/components/Requests/RequestCard.tsx @@ -5,7 +5,6 @@ import img1 from "@/assets/images/no-image.jpeg"; import RequestStatus from "./RequestStatus"; import { MdLocationOn } from "react-icons/md"; import RequestProcessIcon from "./RequestProcessIcon"; -import RequestViolation from "./RequestViolation"; import RequestLike from "./RequestLike"; import RequestComments from "./RequestComments"; import Link from "next/link"; @@ -16,6 +15,7 @@ import { useRouter } from "next/navigation"; import RequestViolations from "./RequestViolations"; import { postReportViolation } from "@/utils/CitizenReport"; +import RequestProcess from "./RequestProcess"; // interface RequestCardProps { // isSelfRequest?: boolean; @@ -124,7 +124,8 @@ const RequestCard: React.FC = ({ item, isSelfRequest }) => {
- + {/* */} +
{/* */} diff --git a/components/Requests/RequestComment.tsx b/components/Requests/RequestComment.tsx index af5eea0..7983eda 100644 --- a/components/Requests/RequestComment.tsx +++ b/components/Requests/RequestComment.tsx @@ -1,7 +1,6 @@ "use client"; import React from "react"; -import { convertFullTime } from "@/lib/utils"; -import RequestViolation from "./RequestViolation"; +import { convertFullTime } from "@/lib/utils"; import { BsTrash3 } from "react-icons/bs"; import ph from "@/assets/images/ph.png"; import Image from "next/image"; diff --git a/components/Requests/RequestComments.tsx b/components/Requests/RequestComments.tsx index f87a82d..5acc0a4 100644 --- a/components/Requests/RequestComments.tsx +++ b/components/Requests/RequestComments.tsx @@ -95,7 +95,7 @@ const RequestComments: React.FC = ({ return ( <> - + e.stopPropagation()}> @@ -120,7 +120,6 @@ const RequestComments: React.FC = ({
{comments.map((comment) => ( <> - {console.log(comment)} = ({ }; export default RequestComments; + diff --git a/components/Requests/RequestProcess.tsx b/components/Requests/RequestProcess.tsx new file mode 100644 index 0000000..9046537 --- /dev/null +++ b/components/Requests/RequestProcess.tsx @@ -0,0 +1,139 @@ +"use client"; +import React, { useEffect, useState } from "react"; +import { CgMenuRightAlt } from "react-icons/cg"; +import { + Drawer, + DrawerClose, + DrawerContent, + DrawerDescription, + DrawerFooter, + DrawerHeader, + DrawerTitle, + DrawerTrigger, +} from "@/components/ui/drawer"; +import { Button } from "../ui/button"; +import { IoClose } from "react-icons/io5"; +import { useQuery } from "@tanstack/react-query"; +import { getReportHistory } from "@/utils/CitizenReport"; +import { convertDate, convertFullTime, convertTime } from "@/lib/utils"; +import { log } from "console"; + +// Define types for props +interface RequestProcessProps { + reportId: string; +} + +interface Media { + url3: string; +} + +interface Reason { + description: string; + id: number; + reasonMeaning: number; + title: string; + transitions: []; +} + +// Define types for History +interface History { + id: string; + message: string; + attachments: Media[]; + dateTime: string; + isPublic: boolean; + reason: Reason; +} + +const RequestProcess: React.FC = ({ reportId }) => { + // Component state + const [history, setHistory] = useState([]); + const [step, setStep] = useState(); + // const [step, setStep] = useState(); + + const { data, isLoading, isError, isSuccess, refetch } = useQuery({ + queryKey: ["History", reportId], + queryFn: () => getReportHistory(reportId), + // refetchOnWindowFocus: false, + }); + + // let newArr = []; + useEffect(() => { + console.log("Fetched data:", data); // Log the fetched data + if (data) { + setHistory(data?.data); + setStep(data?.data?.length); + + // for (let i = 1; i <= data.data.length; i++) { + // // setStep.push(i); + // newArr.push(i); + // } + console.log("History state updated:", data); + console.log("🚀 ~ useEffect ~ data?.data?.length:", data?.data?.length); + } + + console.log("🚀 ~ useEffect ~ setStep:", step); + }, [data]); + + return ( +
+ + e.stopPropagation()}> +
+ + مشاهده روند بررسی +
+
+ + + + {history.map((history, index, array) => ( + <> +
    +
  1. + + {array.length - index} + +
    +
    + {history.message} +
    +
    0 && + `border-b-[1px] border-blue` + }`} + > + {history?.reason?.title} +
    +
    + +
    +
    +
  2. + + {convertTime(history.dateTime)} + + + {convertDate(history.dateTime)} + +
+ + ))} + + + + + +
+
+
+ ); +}; + +export default RequestProcess; diff --git a/components/Requests/RequestViolation.tsx b/components/Requests/RequestViolation.tsx deleted file mode 100644 index 6b17bf8..0000000 --- a/components/Requests/RequestViolation.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import React from "react"; -import { FaRegFlag } from "react-icons/fa6"; - -const RequestViolation = () => { - return ; -}; - -export default RequestViolation; diff --git a/lib/utils.ts b/lib/utils.ts index 3b4f407..73337f2 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -14,10 +14,20 @@ export function convertDate(date: string) { const convertedDate = dayjs(date + "Z") .calendar("jalali") .locale("fa") - .format("YYYY/M/DD"); + .format("YYYY/MM/DD"); return convertedDate; } + +export function convertTime(date: string) { + const convertedDate = dayjs(date + "Z") + .calendar("jalali") + .locale("fa") + .format("HH:mm:ss"); + return convertedDate; +} + + export function convertFullTime(date: string) { const convertedDate = dayjs(date + "Z") .calendar("jalali") diff --git a/package-lock.json b/package-lock.json index 7abf1cf..a6759d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,8 @@ "clsx": "^2.1.0", "cookies-next": "^4.1.1", "dayjs": "^1.11.11", + "flowbite": "^2.3.0", + "flowbite-react": "^0.9.0", "framer-motion": "^11.1.7", "jalaliday": "^2.3.0", "jwt-decode": "^4.0.0", @@ -180,6 +182,20 @@ "@floating-ui/utils": "^0.2.0" } }, + "node_modules/@floating-ui/react": { + "version": "0.26.10", + "resolved": "https://registry.npmjs.org/@floating-ui/react/-/react-0.26.10.tgz", + "integrity": "sha512-sh6f9gVvWQdEzLObrWbJ97c0clJObiALsFe0LiR/kb3tDRKwEhObASEH2QyfdoO/ZBPzwxa9j+nYFo+sqgbioA==", + "dependencies": { + "@floating-ui/react-dom": "^2.0.0", + "@floating-ui/utils": "^0.2.0", + "tabbable": "^6.0.0" + }, + "peerDependencies": { + "react": ">=16.8.0", + "react-dom": ">=16.8.0" + } + }, "node_modules/@floating-ui/react-dom": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/@floating-ui/react-dom/-/react-dom-2.1.0.tgz", @@ -568,6 +584,15 @@ "node": ">=14" } }, + "node_modules/@popperjs/core": { + "version": "2.11.8", + "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz", + "integrity": "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/popperjs" + } + }, "node_modules/@radix-ui/number": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@radix-ui/number/-/number-1.0.1.tgz", @@ -2111,6 +2136,11 @@ "node": ">=6" } }, + "node_modules/classnames": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/classnames/-/classnames-2.5.1.tgz", + "integrity": "sha512-saHYOzhIQs6wy2sVxTM6bUDsQO4F50V9RQ22qBpEdCW+I+/Wmke2HOl6lS6dTpdxVhb88/I6+Hs+438c3lfUow==" + }, "node_modules/client-only": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/client-only/-/client-only-0.0.1.tgz", @@ -2303,6 +2333,17 @@ "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.11.tgz", "integrity": "sha512-okzr3f11N6WuqYtZSvm+F776mB41wRZMhKP+hc34YdW+KmtYYK9iqvHSwo2k9FEH3fhGXvOPV6yz2IcSrfRUDg==" }, + "node_modules/debounce": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/debounce/-/debounce-2.0.0.tgz", + "integrity": "sha512-xRetU6gL1VJbs85Mc4FoEGSjQxzpdxRyFhe3lmWFyy2EzydIcD4xzUvRJMD+NPDfMwKNhxa3PvsIOU32luIWeA==", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -3162,6 +3203,50 @@ "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", "dev": true }, + "node_modules/flowbite": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/flowbite/-/flowbite-2.3.0.tgz", + "integrity": "sha512-pm3JRo8OIJHGfFYWgaGpPv8E+UdWy0Z3gEAGufw+G/1dusaU/P1zoBLiQpf2/+bYAi+GBQtPVG86KYlV0W+AFQ==", + "dependencies": { + "@popperjs/core": "^2.9.3", + "mini-svg-data-uri": "^1.4.3" + } + }, + "node_modules/flowbite-react": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/flowbite-react/-/flowbite-react-0.9.0.tgz", + "integrity": "sha512-wRGzTPHaEuRSXiAFhdTuksezABE/AjI/iyOOBGZpsFAz/sq7zuorAqjRud9FWgy3TlFPtldl7kL93wNY2nOnKQ==", + "dependencies": { + "@floating-ui/core": "1.6.0", + "@floating-ui/react": "0.26.10", + "classnames": "2.5.1", + "debounce": "2.0.0", + "flowbite": "2.3.0", + "react-icons": "5.0.1", + "tailwind-merge": "2.2.2" + }, + "peerDependencies": { + "react": ">=18", + "react-dom": ">=18", + "tailwindcss": "^3" + } + }, + "node_modules/flowbite-react/node_modules/@floating-ui/core": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.6.0.tgz", + "integrity": "sha512-PcF++MykgmTj3CIyOQbKA/hDzOAiqI3mhuoN44WRCopIs1sgoDoU4oty4Jtqaj/y3oDU6fnVSm4QG0a3t5i0+g==", + "dependencies": { + "@floating-ui/utils": "^0.2.1" + } + }, + "node_modules/flowbite-react/node_modules/react-icons": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/react-icons/-/react-icons-5.0.1.tgz", + "integrity": "sha512-WqLZJ4bLzlhmsvme6iFdgO8gfZP17rfjYEJ2m9RsZjZ+cc4k1hTzknEz63YS1MeT50kVzoa1Nz36f4BEx+Wigw==", + "peerDependencies": { + "react": "*" + } + }, "node_modules/follow-redirects": { "version": "1.15.6", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", @@ -4372,6 +4457,14 @@ "node": ">= 0.6" } }, + "node_modules/mini-svg-data-uri": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/mini-svg-data-uri/-/mini-svg-data-uri-1.4.4.tgz", + "integrity": "sha512-r9deDe9p5FJUPZAk3A59wGH7Ii9YrjjWw0jmw/liSbHl2CHiyXj6FcDXDu2K3TjVAXqiJdaw3xxwlZZr9E6nHg==", + "bin": { + "mini-svg-data-uri": "cli.js" + } + }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -5950,6 +6043,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/tabbable": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/tabbable/-/tabbable-6.2.0.tgz", + "integrity": "sha512-Cat63mxsVJlzYvN51JmVXIgNoUokrIaT2zLclCXjRd8boZ0004U4KCs/sToJ75C6sdlByWxpYnb5Boif1VSFew==" + }, "node_modules/tailwind-merge": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-2.2.2.tgz", diff --git a/package.json b/package.json index f21b2fc..f2775b0 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,8 @@ "clsx": "^2.1.0", "cookies-next": "^4.1.1", "dayjs": "^1.11.11", + "flowbite": "^2.3.0", + "flowbite-react": "^0.9.0", "framer-motion": "^11.1.7", "jalaliday": "^2.3.0", "jwt-decode": "^4.0.0", diff --git a/tailwind.config.ts b/tailwind.config.ts index 037f70f..be7695a 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -3,6 +3,9 @@ import type { Config } from "tailwindcss"; const config = { darkMode: ["class"], content: [ + "./node_modules/flowbite-react/lib/**/*.js", + "./node_modules/flowbite/**/*.js", + "./pages/**/*.{ts,tsx}", "./components/**/*.{ts,tsx}", "./app/**/*.{ts,tsx}", @@ -91,7 +94,7 @@ const config = { }, }, }, - plugins: [require("tailwindcss-animate"), require('tailwind-scrollbar')], + plugins: [require("tailwindcss-animate"), require('tailwind-scrollbar'), require("flowbite/plugin")], } satisfies Config; export default config; diff --git a/utils/CitizenReport.ts b/utils/CitizenReport.ts index 3d6dca3..e98a73c 100644 --- a/utils/CitizenReport.ts +++ b/utils/CitizenReport.ts @@ -146,3 +146,10 @@ export async function postReportViolation( const data = await axios.post(`/api/CitizenReport/ReportViolation/${id}`,payload); return data.data; } + + +// Get ReportHistory {ID} +export async function getReportHistory(id: string) { + const data = await axios.get(`/api/CitizenReport/ReportHistory/${id}`); + return data.data; +} \ No newline at end of file