Added part of RequestProcess

master
YasamanKahdooei 2024-06-08 15:31:19 +03:30
parent f8d9513d6a
commit aa78a28b5d
10 changed files with 267 additions and 16 deletions

View File

@ -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<RequestCardProps> = ({ item, isSelfRequest }) => {
</div>
<div className="w-full flex items-center justify-between mb-[10px]">
<RequestProcessIcon />
{/* <RequestProcessIcon /> */}
<RequestProcess reportId={item.id} />
<div className="flex items-center justify-center">
{/* <RequestViolations reportId={item.id} /> */}

View File

@ -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";

View File

@ -95,7 +95,7 @@ const RequestComments: React.FC<RequestCommentsProps> = ({
return (
<>
<span className="flex items-center justify-center text-black text-lg font-bold">
<Drawer>
<Drawer direction='bottom'>
<DrawerTrigger onClick={(e) => e.stopPropagation()}>
<FaRegComment className="mx-1 cursor-pointer" />
</DrawerTrigger>
@ -120,7 +120,6 @@ const RequestComments: React.FC<RequestCommentsProps> = ({
<div>
{comments.map((comment) => (
<>
{console.log(comment)}
<RequestComment
key={comment.id}
id={comment.id}
@ -180,3 +179,4 @@ const RequestComments: React.FC<RequestCommentsProps> = ({
};
export default RequestComments;

View File

@ -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<RequestProcessProps> = ({ reportId }) => {
// Component state
const [history, setHistory] = useState<History[]>([]);
const [step, setStep] = useState<number>();
// 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 (
<div className="">
<Drawer direction="right">
<DrawerTrigger onClick={(e) => e.stopPropagation()}>
<div className="text-xs text-gray-500 flex items-center cursor-pointer rounded-md">
<CgMenuRightAlt className="ml-1 text-lg" />
<span>مشاهده روند بررسی</span>
</div>
</DrawerTrigger>
<DrawerContent className=" px-20 w-1/2 h-screen z-[1000] overflow-y-auto scrollbar-thin scrollbar-thumb-yellow scrollbar-track-white">
<DrawerHeader className="mb-4"></DrawerHeader>
{history.map((history, index, array) => (
<>
<ol
key={history.id}
className="relative border-s border-gray-300 dark:border-gray-700 mr-48"
>
<li className="mb-10 ms-6">
<span className="absolute flex items-center justify-center w-8 h-8 bg-blue-100 rounded-full -start-4 ring-8 ring-white bg-blue2 ">
{array.length - index}
</span>
<div className=" bg-white border-2 border-gray-300 rounded-lg shadow-sm dark:bg-gray-700 dark:border-gray-600 w-full">
<div className="flex items-center justify-center bg-blue text-white rounded-t-lg p-2 border-2 text-sm">
{history.message}
</div>
<div
className={`p-5 m-1 italic font-normal text-black rounded-lg text-sm text-center ${
history?.attachments?.length > 0 &&
`border-b-[1px] border-blue`
}`}
>
{history?.reason?.title}
</div>
<div>
</div>
</div>
</li>
<span className="absolute -right-44 top-0 ">
{convertTime(history.dateTime)}
</span>
<span className="absolute -right-44 top-5 ">
{convertDate(history.dateTime)}
</span>
</ol>
</>
))}
<DrawerFooter className=" absolute top-0 left-0 w-14 h-14">
<DrawerClose asChild>
<Button variant="outline" className="p-0 border-0">
<IoClose className=" w-full h-full text-gray-600" />
</Button>
</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>
</div>
);
};
export default RequestProcess;

View File

@ -1,8 +0,0 @@
import React from "react";
import { FaRegFlag } from "react-icons/fa6";
const RequestViolation = () => {
return <FaRegFlag className="text-lg mx-1 cursor-pointer" />;
};
export default RequestViolation;

View File

@ -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")

98
package-lock.json generated
View File

@ -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",

View File

@ -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",

View File

@ -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;

View File

@ -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;
}