From 47c79aff83f64272d04e8389fbc6959aadde646d Mon Sep 17 00:00:00 2001 From: YasamanKahdooei Date: Thu, 16 May 2024 16:01:40 +0330 Subject: [PATCH] added "Like section" in Request card , RTL mapbox , Query for CitizinRequest , ExpireToken --- app/User/MyRequest/page.tsx | 3 +- app/User/layout.tsx | 10 +- app/layout.tsx | 22 +++ components/RecentRequest/OnMapRequests.tsx | 102 +++++++---- components/RecentRequest/RecentRequests.tsx | 2 +- components/RecentRequest/RequestList.tsx | 3 +- components/Requests/RequestCard.tsx | 27 +-- components/Requests/RequestLike.tsx | 126 +++++++++++++- components/Requests/RequestStatus.tsx | 30 +++- lib/utils.ts | 2 +- package-lock.json | 178 ++++++++++++-------- package.json | 2 + utils/CitizenReport.ts | 125 +++++++++++--- utils/authenticateApi.ts | 29 ++-- 14 files changed, 499 insertions(+), 162 deletions(-) diff --git a/app/User/MyRequest/page.tsx b/app/User/MyRequest/page.tsx index 9625b94..d1a2e45 100644 --- a/app/User/MyRequest/page.tsx +++ b/app/User/MyRequest/page.tsx @@ -4,9 +4,10 @@ import React from "react"; export default function page() { return ( -
+
{/* */}
+ // ); } diff --git a/app/User/layout.tsx b/app/User/layout.tsx index e22f4ea..338bbd4 100644 --- a/app/User/layout.tsx +++ b/app/User/layout.tsx @@ -1,17 +1,25 @@ import SideMenu from "@/components/Menu/SideMenu"; import UserHeader from "@/components/User/UserHeader"; +import { cookies } from "next/headers"; +import { redirect } from "next/navigation"; export default function RequestLayout({ children, // will be a page or nested layout }: { children: React.ReactNode; }) { + const cookieStore = cookies(); + const token = cookieStore.get("Shahrbin_Token"); + if (!token) { + redirect("/"); + } + return (
{/* Include shared UI here e.g. a header or sidebar */} -
{children}
+
{children}
); } diff --git a/app/layout.tsx b/app/layout.tsx index 5f1878e..3410c88 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -7,6 +7,28 @@ import ProgressBarProviders from "@/components/ProgressBar/ProgressBar"; const inter = Inter({ subsets: ["latin"] }); +// mapboxgl.setRTLTextPlugin( +// "https://cdn.parsimap.ir/third-party/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js", +// null +// ); + +// mapboxgl.setRTLTextPlugin( +// "https://cdn.parsimap.ir/third-party/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js", +// (error) => { +// if (error) { +// console.error('Failed to load RTL text plugin:', error); +// } +// } +// ); + + +// mapboxgl.setRTLTextPlugin( +// "https://cdn.parsimap.ir/third-party/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js", +// () => {} +// ); + + + export const metadata: Metadata = { title: "Create Next App", description: "Generated by create next app", diff --git a/components/RecentRequest/OnMapRequests.tsx b/components/RecentRequest/OnMapRequests.tsx index 148a3b1..22ef1db 100644 --- a/components/RecentRequest/OnMapRequests.tsx +++ b/components/RecentRequest/OnMapRequests.tsx @@ -7,9 +7,13 @@ import ReactMapboxGl, { Marker, ZoomControl } from "react-mapbox-gl"; import marker from "@/assets/images/location.svg"; import RequestCard from "../Requests/RequestCard"; import { cn } from "@/lib/utils"; +import mapboxgl from "mapbox-gl"; const accessToken = process.env.REACT_APP_ACCESS_TOKEN || ""; - +mapboxgl.setRTLTextPlugin( + "https://cdn.parsimap.ir/third-party/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js", + () => {} +); const MapContainer = ReactMapboxGl({ accessToken: accessToken, minZoom: 8, @@ -17,24 +21,37 @@ const MapContainer = ReactMapboxGl({ // zoom: 9, }); +interface MyItemType { + id: number; + name: string; + description: string; + abbreviation: string; + cityId: number; + city: string; + englishName: string; + latitude: number; + longitude: number; +} const OnMapRequests = () => { const [selected, setSelected] = useState(null); - const [citizenInstance, setCitizenInstance] = useState(null); + const [citizenInstance, setCitizenInstance] = useState( + null + ); const [locations, setLocations] = useState(null); useEffect(() => { const CtizenInstances = localStorage.getItem("SH_CT_INSTANCE"); - setCitizenInstance(CtizenInstances); - console.log("🚀 ~ useEffect ~ CtizenInstancessssss:", citizenInstance); - console.log("🚀 ~ useEffect ~ CtizenInstancessssssss:", CtizenInstances); - - const defaultCoords = { - // latitude: citizenInstance.latitude, - // longitude: citizenInstance.longitude, - }; + if (CtizenInstances) { + const parsedItem = JSON.parse(CtizenInstances); + setCitizenInstance(parsedItem); + } }, [citizenInstance]); + const defaultCoords = { + latitude: citizenInstance?.latitude || 0, + longitude: citizenInstance?.longitude || 0, + }; // refs const detailsRef = useRef(null); const wrappersRef = useRef(null); @@ -74,18 +91,10 @@ const OnMapRequests = () => { useEffect(() => { if (LocationData) { - console.log("🚀 ~ OnMapRequests ~ LocationData:", LocationData); - console.log( - "🚀 ~ OnMapRequestssss ~ LocationDataa:", - LocationData?.data?.locations[0]?.locations - ); setLocations(LocationData?.data?.locations[0]?.locations); } }, [isSuccess]); - if (isError) { - console.log("have a errorrrrrrr "); - } return (
@@ -104,22 +113,14 @@ const OnMapRequests = () => {
) : ( {locations?.map((d: any) => ( - + {/* showDetails(d)} /> */} @@ -141,6 +142,7 @@ const OnMapRequests = () => { {selected && } */} + )} @@ -150,4 +152,44 @@ const OnMapRequests = () => { ); }; -export default OnMapRequests; +export default OnMapRequests; +// return ( +//
+// +//
+// ); +// } + +// if (isError) { +// return

Map Failed

; +// } + +// return ( +//
+// +// {locations?.map((d: any) => ( +// +// +// +// ))} +// +// +//
+// ); +// }; + +// export default OnMapRequests; \ No newline at end of file diff --git a/components/RecentRequest/RecentRequests.tsx b/components/RecentRequest/RecentRequests.tsx index d906649..33133b2 100644 --- a/components/RecentRequest/RecentRequests.tsx +++ b/components/RecentRequest/RecentRequests.tsx @@ -41,7 +41,7 @@ function RecentRequests() { {/* Right */}
- + {/* */}
diff --git a/components/RecentRequest/RequestList.tsx b/components/RecentRequest/RequestList.tsx index 5ead111..123c855 100644 --- a/components/RecentRequest/RequestList.tsx +++ b/components/RecentRequest/RequestList.tsx @@ -3,7 +3,8 @@ import RequestCard from "../Requests/RequestCard"; const RequestList = () => { return ( -
+
+ {/*
*/}
); diff --git a/components/Requests/RequestCard.tsx b/components/Requests/RequestCard.tsx index bd1d5ee..d453b38 100644 --- a/components/Requests/RequestCard.tsx +++ b/components/Requests/RequestCard.tsx @@ -24,7 +24,7 @@ const RequestCard: React.FC = ({ isSelfRequest = false }) => { queryKey: ["CitizenReport"], queryFn: () => getCitizenReport({ PageNumber: 1, PageSize: 10, instanceId: 1 }), - refetchOnWindowFocus: false, + // refetchOnWindowFocus: false, }); useEffect(() => { @@ -37,11 +37,13 @@ const RequestCard: React.FC = ({ isSelfRequest = false }) => { }, [data]); return ( -
+ //
+ <> {reportData?.map((item: any) => { return ( - = ({ isSelfRequest = false }) => { quality={100} height={100} width={100} - className="w-full h-full rounded-md object-contain" + className="w-[80%] h-full rounded-md object-contain" />
{/* 1 requestCardInfoRow */} -
+

{item.categoryTitle}

@@ -71,7 +73,7 @@ const RequestCard: React.FC = ({ isSelfRequest = false }) => {
{/* 2 */} -
+

{item.addressDetail}

@@ -79,7 +81,7 @@ const RequestCard: React.FC = ({ isSelfRequest = false }) => {
{/* 3 */} -
+
کد رهگیری: {item.trackingNumber} @@ -90,19 +92,20 @@ const RequestCard: React.FC = ({ isSelfRequest = false }) => {
{/* 4 */} -
+
- +
- +
); })} -
+ + //
); }; diff --git a/components/Requests/RequestLike.tsx b/components/Requests/RequestLike.tsx index 58d64c3..2584efa 100644 --- a/components/Requests/RequestLike.tsx +++ b/components/Requests/RequestLike.tsx @@ -1,14 +1,130 @@ -import React from "react"; +"use client"; +import React, { useState } from "react"; import { FiHeart } from "react-icons/fi"; -import { IoMdHeart } from "react-icons/io"; +import { FcLike } from "react-icons/fc"; +import { GoHeart } from "react-icons/go"; +import { PiHeart } from "react-icons/pi"; + +import { ImHeart } from "react-icons/im"; +import { SlHeart } from "react-icons/sl"; +import { useQuery } from "@tanstack/react-query"; +import { useParams } from "next/navigation"; +import { SetLike } from "@/utils/CitizenReport"; + +// const RequestLike = ({ RequestId = "" }) => { +// const id = RequestId; +// // const params = useParams<{ tag: string; item: string }>(); + +// // states +// const [isLiked, setIsLiked] = useState(false); +// const [likes, setLikes] = useState(0); + +// const onLike = async (isLiked: boolean) => { +// setIsLiked(isLiked); +// const params = { +// reportId: id, +// // isLiked: !isLiked, // Toggle the like status +// isLiked, +// }; + +// try { +// const { data, isLoading, isError, isSuccess, refetch } = useQuery({ +// queryKey: ["CitizenLike"], +// queryFn: () => +// SetLike({ +// id: params.reportId, +// isLiked: params.isLiked, +// }), +// refetchOnWindowFocus: false, +// }); + +// if (isSuccess) { +// console.log(data); +// setLikes((prevLikes) => (isLiked ? prevLikes + 1 : prevLikes - 1)); +// console.log("Likkeee"); +// } else { +// setIsLiked(!isLiked); +// console.log("DisssLikkeee"); +// } +// } catch (err) { +// setIsLiked(!isLiked); +// } +// }; + +// return ( +// <> +// +// {isLiked ? ( +// { +// e.stopPropagation(); +// onLike(!isLiked); +// }} +// /> +// ) : ( +// { +// e.stopPropagation(); +// onLike(!isLiked); +// }} +// /> +// )} +// +// {likes} +// +// ); +// }; + +// export default RequestLike; + +// Define types for props +interface RequestLikeProps { + reportId: string; + initialIsLiked: boolean; + initialLikes: number; +} +// Define the RequestLike component +const RequestLike: React.FC = ({ + reportId, + initialIsLiked, + initialLikes, +}) => { + // Component state + const [isLiked, setIsLiked] = useState(initialIsLiked); + const [likes, setLikes] = useState(initialLikes); + + // Handle the PUT request + const onLike = async ( + newIsLiked: boolean, + event: React.MouseEvent + ) => { + event.stopPropagation(); + try { + await SetLike({ id: reportId, isLiked: newIsLiked }); + setIsLiked(newIsLiked); + setLikes((prevLikes) => (newIsLiked ? prevLikes + 1 : prevLikes - 1)); + } catch (error) { + console.error("Error liking the report:", error); + } + }; -const RequestLike = () => { return ( <> - + {isLiked ? ( + onLike(!isLiked, e)} + /> + ) : ( + onLike(!isLiked, e)} + /> + )} - 0 + {likes} ); }; diff --git a/components/Requests/RequestStatus.tsx b/components/Requests/RequestStatus.tsx index d45c362..ca4566a 100644 --- a/components/Requests/RequestStatus.tsx +++ b/components/Requests/RequestStatus.tsx @@ -1,13 +1,41 @@ +// import { statusColors } from "@/utils/variables"; import React from "react"; interface RequestStatusProps { lastStatus?: String; } +interface StatusColors { + [key: string]: string; +} + +export const statusColors: StatusColors = { + "در انتظار تأیید اپراتور": "bg-yellow", + "ارجاع به واحد اجرایی": "bg-gray-400", + "ارجاع به پیمانکار": "bg-purple-500", + "پایان یافته": "bg-lightGreen", + "ارجاع به واحد بازرسی": "bg-red", + "بررسی توسط واحد بازرسی": "bg-red", + "ثبت درخواست در سامانه": "bg-blue2", + "در انتظار تأیید در سامانه": "bg-blue3", + "تأیید درخواست در سامانه": "#79B473", + "ارجاع به شهروند": "bg-purple-800", + "ارجاع به اپراتور": "bg-blue", + "پاسخ به شهروند": "bg-purple-800", + "ایجاد شده": "bg-yellow", + "در حال بررسی": "bg-gray-400", +}; const RequestStatus: React.FC = ({ lastStatus }) => { + + + const statusColorClass = lastStatus && statusColors[lastStatus.toLowerCase()]; return ( <> - + {lastStatus} diff --git a/lib/utils.ts b/lib/utils.ts index 4da7a76..3b4f407 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -22,6 +22,6 @@ export function convertFullTime(date: string) { const convertedDate = dayjs(date + "Z") .calendar("jalali") .locale("fa") - .format(" HH:mm ساعت YYYY/MM/DD"); + .format("DD MMMM YYYY ساعت HH:mm "); return convertedDate; } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 24af450..9330adf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "jalaliday": "^2.3.0", "jwt-decode": "^4.0.0", "lucide-react": "^0.365.0", + "mapbox-gl": "^3.3.0", "next": "14.1.4", "next-nprogress-bar": "^2.3.11", "next-themes": "^0.3.0", @@ -43,6 +44,7 @@ "zustand": "^4.5.2" }, "devDependencies": { + "@types/mapbox-gl": "^3.1.0", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", @@ -288,7 +290,6 @@ "version": "0.5.2", "resolved": "https://registry.npmjs.org/@mapbox/geojson-rewind/-/geojson-rewind-0.5.2.tgz", "integrity": "sha512-tJaT+RbYGJYStt7wI3cq4Nl4SXxG8W7JDG5DMJu97V25RnbNg3QtQtf+KD+VLjNpWKYsRvXDNmNrBgEETr1ifA==", - "peer": true, "dependencies": { "get-stream": "^6.0.1", "minimist": "^1.2.6" @@ -297,53 +298,38 @@ "geojson-rewind": "geojson-rewind" } }, - "node_modules/@mapbox/geojson-types": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@mapbox/geojson-types/-/geojson-types-1.0.2.tgz", - "integrity": "sha512-e9EBqHHv3EORHrSfbR9DqecPNn+AmuAoQxV6aL8Xu30bJMJR1o8PZLZzpk1Wq7/NfCbuhmakHTPYRhoqLsXRnw==", - "peer": true - }, "node_modules/@mapbox/jsonlint-lines-primitives": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/@mapbox/jsonlint-lines-primitives/-/jsonlint-lines-primitives-2.0.2.tgz", "integrity": "sha512-rY0o9A5ECsTQRVhv7tL/OyDpGAoUB4tTvLiW1DSzQGq4bvTPhNw1VpSNjDJc5GFZ2XuyOtSWSVN05qOtcD71qQ==", - "peer": true, "engines": { "node": ">= 0.6" } }, "node_modules/@mapbox/mapbox-gl-supported": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@mapbox/mapbox-gl-supported/-/mapbox-gl-supported-1.5.0.tgz", - "integrity": "sha512-/PT1P6DNf7vjEEiPkVIRJkvibbqWtqnyGaBz3nfRdcxclNSnSdaLU5tfAgcD7I8Yt5i+L19s406YLl1koLnLbg==", - "peer": true, - "peerDependencies": { - "mapbox-gl": ">=0.32.1 <2.0.0" - } + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@mapbox/mapbox-gl-supported/-/mapbox-gl-supported-3.0.0.tgz", + "integrity": "sha512-2XghOwu16ZwPJLOFVuIOaLbN0iKMn867evzXFyf0P22dqugezfJwLmdanAgU25ITvz1TvOfVP4jsDImlDJzcWg==" }, "node_modules/@mapbox/point-geometry": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/@mapbox/point-geometry/-/point-geometry-0.1.0.tgz", - "integrity": "sha512-6j56HdLTwWGO0fJPlrZtdU/B13q8Uwmo18Ck2GnGgN9PCFyKTZ3UbXeEdRFh18i9XQ92eH2VdtpJHpBD3aripQ==", - "peer": true + "integrity": "sha512-6j56HdLTwWGO0fJPlrZtdU/B13q8Uwmo18Ck2GnGgN9PCFyKTZ3UbXeEdRFh18i9XQ92eH2VdtpJHpBD3aripQ==" }, "node_modules/@mapbox/tiny-sdf": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/@mapbox/tiny-sdf/-/tiny-sdf-1.2.5.tgz", - "integrity": "sha512-cD8A/zJlm6fdJOk6DqPUV8mcpyJkRz2x2R+/fYcWDYG3oWbG7/L7Yl/WqQ1VZCjnL9OTIMAn6c+BC5Eru4sQEw==", - "peer": true + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/@mapbox/tiny-sdf/-/tiny-sdf-2.0.6.tgz", + "integrity": "sha512-qMqa27TLw+ZQz5Jk+RcwZGH7BQf5G/TrutJhspsca/3SHwmgKQ1iq+d3Jxz5oysPVYTGP6aXxCo5Lk9Er6YBAA==" }, "node_modules/@mapbox/unitbezier": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/@mapbox/unitbezier/-/unitbezier-0.0.0.tgz", - "integrity": "sha512-HPnRdYO0WjFjRTSwO3frz1wKaU649OBFPX3Zo/2WZvuRi6zMiRGui8SnPQiQABgqCf8YikDe5t3HViTVw1WUzA==", - "peer": true + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@mapbox/unitbezier/-/unitbezier-0.0.1.tgz", + "integrity": "sha512-nMkuDXFv60aBr9soUG5q+GvZYL+2KZHVvsqFCzqnkGEf46U2fvmytHaEVc1/YZbiLn8X+eR3QzX1+dwDO1lxlw==" }, "node_modules/@mapbox/vector-tile": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/@mapbox/vector-tile/-/vector-tile-1.3.1.tgz", "integrity": "sha512-MCEddb8u44/xfQ3oD+Srl/tNcQoqTw3goGk2oLsrFxOTc3dUp+kAnby3PvAeeBYSMSjSPD1nd1AJA6W49WnoUw==", - "peer": true, "dependencies": { "@mapbox/point-geometry": "~0.1.0" } @@ -352,7 +338,6 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/@mapbox/whoots-js/-/whoots-js-3.1.0.tgz", "integrity": "sha512-Es6WcD0nO5l+2BOQS4uLfNPYQaNDfbot3X1XUoloz+x0mPDS3eeORZJl06HXjwBG1fOGwCRnzK88LMdxKRrd6Q==", - "peer": true, "engines": { "node": ">=6.0.0" } @@ -1073,6 +1058,15 @@ "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", "dev": true }, + "node_modules/@types/mapbox-gl": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@types/mapbox-gl/-/mapbox-gl-3.1.0.tgz", + "integrity": "sha512-hI6cQDjw1bkJw7MC/eHMqq5TWUamLwsujnUUeiIX2KDRjxRNSYMjnHz07+LATz9I9XIsKumOtUz4gRYnZOJ/FA==", + "dev": true, + "dependencies": { + "@types/geojson": "*" + } + }, "node_modules/@types/node": { "version": "20.12.4", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.4.tgz", @@ -1767,6 +1761,11 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, + "node_modules/cheap-ruler": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/cheap-ruler/-/cheap-ruler-3.0.2.tgz", + "integrity": "sha512-02T332h1/HTN6cDSufLP8x4JzDs2+VC+8qZ/N0kWIVPyc2xUkWwWh3B2fJxR7raXkL4Mq7k554mfuM9ofv/vGg==" + }, "node_modules/chokidar": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", @@ -1931,8 +1930,7 @@ "node_modules/csscolorparser": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/csscolorparser/-/csscolorparser-1.0.3.tgz", - "integrity": "sha512-umPSgYwZkdFoUrH5hIq5kf0wPSXiro51nPw0j2K/c83KflkPSTBGMz6NJvMB+07VlL0y7VPo6QJcDjcgKTTm3w==", - "peer": true + "integrity": "sha512-umPSgYwZkdFoUrH5hIq5kf0wPSXiro51nPw0j2K/c83KflkPSTBGMz6NJvMB+07VlL0y7VPo6QJcDjcgKTTm3w==" }, "node_modules/cssesc": { "version": "3.0.0", @@ -2129,8 +2127,7 @@ "node_modules/earcut": { "version": "2.2.4", "resolved": "https://registry.npmjs.org/earcut/-/earcut-2.2.4.tgz", - "integrity": "sha512-/pjZsA1b4RPHbeWZQn66SWS8nZZWLQQ23oE3Eam7aroEFGEvwKAsJfZ9ytiEMycfzXWpca4FA9QIOehf7PocBQ==", - "peer": true + "integrity": "sha512-/pjZsA1b4RPHbeWZQn66SWS8nZZWLQQ23oE3Eam7aroEFGEvwKAsJfZ9ytiEMycfzXWpca4FA9QIOehf7PocBQ==" }, "node_modules/eastasianwidth": { "version": "0.2.0", @@ -2804,6 +2801,11 @@ "reusify": "^1.0.4" } }, + "node_modules/fflate": { + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.2.tgz", + "integrity": "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A==" + }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -3013,8 +3015,7 @@ "node_modules/geojson-vt": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/geojson-vt/-/geojson-vt-3.2.1.tgz", - "integrity": "sha512-EvGQQi/zPrDA6zr6BnJD/YhwAkBP8nnJ9emh3EnHQKVMfg/MRVtPbMYdgVy/IaEmn4UfagD2a6fafPDL5hbtwg==", - "peer": true + "integrity": "sha512-EvGQQi/zPrDA6zr6BnJD/YhwAkBP8nnJ9emh3EnHQKVMfg/MRVtPbMYdgVy/IaEmn4UfagD2a6fafPDL5hbtwg==" }, "node_modules/get-intrinsic": { "version": "1.2.4", @@ -3039,7 +3040,6 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", - "peer": true, "engines": { "node": ">=10" }, @@ -3079,8 +3079,7 @@ "node_modules/gl-matrix": { "version": "3.4.3", "resolved": "https://registry.npmjs.org/gl-matrix/-/gl-matrix-3.4.3.tgz", - "integrity": "sha512-wcCp8vu8FT22BnvKVPjXa/ICBWRq/zjFfdofZy1WSpQZpphblv12/bOQLBC1rMM7SGOFS9ltVmKOHil5+Ml7gA==", - "peer": true + "integrity": "sha512-wcCp8vu8FT22BnvKVPjXa/ICBWRq/zjFfdofZy1WSpQZpphblv12/bOQLBC1rMM7SGOFS9ltVmKOHil5+Ml7gA==" }, "node_modules/glob": { "version": "10.3.10", @@ -3212,8 +3211,7 @@ "node_modules/grid-index": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/grid-index/-/grid-index-1.1.0.tgz", - "integrity": "sha512-HZRwumpOGUrHyxO5bqKZL0B0GlUpwtCAzZ42sgxUPniu33R1LSFH5yrIcBCHjkctCAh3mtWKcKd9J4vDDdeVHA==", - "peer": true + "integrity": "sha512-HZRwumpOGUrHyxO5bqKZL0B0GlUpwtCAzZ42sgxUPniu33R1LSFH5yrIcBCHjkctCAh3mtWKcKd9J4vDDdeVHA==" }, "node_modules/has-bigints": { "version": "1.0.2", @@ -3312,8 +3310,7 @@ "type": "consulting", "url": "https://feross.org/support" } - ], - "peer": true + ] }, "node_modules/ignore": { "version": "5.3.1", @@ -3937,6 +3934,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/lodash.clonedeep": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", + "integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==" + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -3971,36 +3973,51 @@ } }, "node_modules/mapbox-gl": { - "version": "1.13.3", - "resolved": "https://registry.npmjs.org/mapbox-gl/-/mapbox-gl-1.13.3.tgz", - "integrity": "sha512-p8lJFEiqmEQlyv+DQxFAOG/XPWN0Wp7j/Psq93Zywz7qt9CcUKFYDBOoOEKzqe6gudHVJY8/Bhqw6VDpX2lSBg==", - "peer": true, + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/mapbox-gl/-/mapbox-gl-3.3.0.tgz", + "integrity": "sha512-cVeAu9PxPTx113AnJAzcSKbBtL5F5EpJ6/NuYgNib9zNduNSoDG2oVX6xK0bAP/VwwVwRh9SEhcyM7nh4GThvQ==", "dependencies": { "@mapbox/geojson-rewind": "^0.5.2", - "@mapbox/geojson-types": "^1.0.2", "@mapbox/jsonlint-lines-primitives": "^2.0.2", - "@mapbox/mapbox-gl-supported": "^1.5.0", + "@mapbox/mapbox-gl-supported": "^3.0.0", "@mapbox/point-geometry": "^0.1.0", - "@mapbox/tiny-sdf": "^1.1.1", - "@mapbox/unitbezier": "^0.0.0", + "@mapbox/tiny-sdf": "^2.0.6", + "@mapbox/unitbezier": "^0.0.1", "@mapbox/vector-tile": "^1.3.1", "@mapbox/whoots-js": "^3.1.0", + "cheap-ruler": "^3.0.1", "csscolorparser": "~1.0.3", - "earcut": "^2.2.2", + "earcut": "^2.2.4", + "fflate": "^0.8.1", "geojson-vt": "^3.2.1", - "gl-matrix": "^3.2.1", + "gl-matrix": "^3.4.3", "grid-index": "^1.1.0", + "kdbush": "^4.0.1", + "lodash.clonedeep": "^4.5.0", "murmurhash-js": "^1.0.0", "pbf": "^3.2.1", - "potpack": "^1.0.1", + "potpack": "^2.0.0", "quickselect": "^2.0.0", "rw": "^1.3.3", - "supercluster": "^7.1.0", + "serialize-to-js": "^3.1.2", + "supercluster": "^8.0.0", + "tiny-lru": "^11.2.5", "tinyqueue": "^2.0.3", - "vt-pbf": "^3.1.1" - }, - "engines": { - "node": ">=6.4.0" + "tweakpane": "^4.0.3", + "vt-pbf": "^3.1.3" + } + }, + "node_modules/mapbox-gl/node_modules/kdbush": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/kdbush/-/kdbush-4.0.2.tgz", + "integrity": "sha512-WbCVYJ27Sz8zi9Q7Q0xHC+05iwkm3Znipc2XTlrnJbsHMYktW4hPhXUE8Ys1engBrvffoSCqbil1JQAa7clRpA==" + }, + "node_modules/mapbox-gl/node_modules/supercluster": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/supercluster/-/supercluster-8.0.1.tgz", + "integrity": "sha512-IiOea5kJ9iqzD2t7QJq/cREyLHTtSmUT6gQsweojg9WH2sYJqZK9SswTu6jrscO6D1G5v5vYZ9ru/eq85lXeZQ==", + "dependencies": { + "kdbush": "^4.0.2" } }, "node_modules/merge2": { @@ -4079,8 +4096,7 @@ "node_modules/murmurhash-js": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/murmurhash-js/-/murmurhash-js-1.0.0.tgz", - "integrity": "sha512-TvmkNhkv8yct0SVBSy+o8wYzXjE4Zz3PCesbfs8HiCXXdcTuocApFv11UWlNFWKYsP2okqrhb7JNlSm9InBhIw==", - "peer": true + "integrity": "sha512-TvmkNhkv8yct0SVBSy+o8wYzXjE4Zz3PCesbfs8HiCXXdcTuocApFv11UWlNFWKYsP2okqrhb7JNlSm9InBhIw==" }, "node_modules/mz": { "version": "2.7.0", @@ -4491,7 +4507,6 @@ "version": "3.2.1", "resolved": "https://registry.npmjs.org/pbf/-/pbf-3.2.1.tgz", "integrity": "sha512-ClrV7pNOn7rtmoQVF4TS1vyU0WhYRnP92fzbfF75jAIwpnzdJXf8iTd4CMEqO4yUenH6NDqLiwjqlh6QgZzgLQ==", - "peer": true, "dependencies": { "ieee754": "^1.1.12", "resolve-protobuf-schema": "^2.1.0" @@ -4683,10 +4698,9 @@ "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==" }, "node_modules/potpack": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/potpack/-/potpack-1.0.2.tgz", - "integrity": "sha512-choctRBIV9EMT9WGAZHn3V7t0Z2pMQyl0EZE6pFc/6ml3ssw7Dlf/oAOvFwjm1HVsqfQN8GfeFyJ+d8tRzqueQ==", - "peer": true + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/potpack/-/potpack-2.0.0.tgz", + "integrity": "sha512-Q+/tYsFU9r7xoOJ+y/ZTtdVQwTWfzjbiXBDMM/JKUux3+QPP02iUuIoeBQ+Ot6oEDlC+/PGjB/5A3K7KKb7hcw==" }, "node_modules/prelude-ls": { "version": "1.2.1", @@ -4710,8 +4724,7 @@ "node_modules/protocol-buffers-schema": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/protocol-buffers-schema/-/protocol-buffers-schema-3.6.0.tgz", - "integrity": "sha512-TdDRD+/QNdrCGCE7v8340QyuXd4kIWIgapsE2+n/SaGiSSbomYl4TjHlvIoCWRpE7wFt02EpB35VVA2ImcBVqw==", - "peer": true + "integrity": "sha512-TdDRD+/QNdrCGCE7v8340QyuXd4kIWIgapsE2+n/SaGiSSbomYl4TjHlvIoCWRpE7wFt02EpB35VVA2ImcBVqw==" }, "node_modules/proxy-from-env": { "version": "1.1.0", @@ -4749,8 +4762,7 @@ "node_modules/quickselect": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/quickselect/-/quickselect-2.0.0.tgz", - "integrity": "sha512-RKJ22hX8mHe3Y6wH/N3wCM6BWtjaxIyyUIkpHOvfFnxdI4yD4tBXEBKSbriGujF6jnSVkJrffuo6vxACiSSxIw==", - "peer": true + "integrity": "sha512-RKJ22hX8mHe3Y6wH/N3wCM6BWtjaxIyyUIkpHOvfFnxdI4yD4tBXEBKSbriGujF6jnSVkJrffuo6vxACiSSxIw==" }, "node_modules/react": { "version": "18.2.0", @@ -4964,7 +4976,6 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/resolve-protobuf-schema/-/resolve-protobuf-schema-2.1.0.tgz", "integrity": "sha512-kI5ffTiZWmJaS/huM8wZfEMer1eRd7oJQhDuxeCLe3t7N7mX3z94CN0xPxBQxFYQTSNz9T0i+v6inKqSdK8xrQ==", - "peer": true, "dependencies": { "protocol-buffers-schema": "^3.3.1" } @@ -5038,8 +5049,7 @@ "node_modules/rw": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/rw/-/rw-1.3.3.tgz", - "integrity": "sha512-PdhdWy89SiZogBLaw42zdeqtRJ//zFd2PgQavcICDUgJT5oW10QCRKbJ6bg4r0/UY2M6BWd5tkxuGFRvCkgfHQ==", - "peer": true + "integrity": "sha512-PdhdWy89SiZogBLaw42zdeqtRJ//zFd2PgQavcICDUgJT5oW10QCRKbJ6bg4r0/UY2M6BWd5tkxuGFRvCkgfHQ==" }, "node_modules/safe-array-concat": { "version": "1.1.2", @@ -5111,6 +5121,14 @@ "node": ">=10" } }, + "node_modules/serialize-to-js": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/serialize-to-js/-/serialize-to-js-3.1.2.tgz", + "integrity": "sha512-owllqNuDDEimQat7EPG0tH7JjO090xKNzUtYz6X+Sk2BXDnOCilDdNLwjWeFywG9xkJul1ULvtUQa9O4pUaY0w==", + "engines": { + "node": ">=4.0.0" + } + }, "node_modules/set-function-length": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", @@ -5653,11 +5671,18 @@ "node": ">=0.8" } }, + "node_modules/tiny-lru": { + "version": "11.2.6", + "resolved": "https://registry.npmjs.org/tiny-lru/-/tiny-lru-11.2.6.tgz", + "integrity": "sha512-0PU3c9PjMnltZaFo2sGYv/nnJsMjG0Cxx8X6FXHPPGjFyoo1SJDxvUXW1207rdiSxYizf31roo+GrkIByQeZoA==", + "engines": { + "node": ">=12" + } + }, "node_modules/tinyqueue": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/tinyqueue/-/tinyqueue-2.0.3.tgz", - "integrity": "sha512-ppJZNDuKGgxzkHihX8v9v9G5f+18gzaTfrukGrq6ueg0lmH4nqVnA2IPG0AEH3jKEk2GRJCUhDoqpoiw3PHLBA==", - "peer": true + "integrity": "sha512-ppJZNDuKGgxzkHihX8v9v9G5f+18gzaTfrukGrq6ueg0lmH4nqVnA2IPG0AEH3jKEk2GRJCUhDoqpoiw3PHLBA==" }, "node_modules/to-regex-range": { "version": "5.0.1", @@ -5704,6 +5729,14 @@ "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" }, + "node_modules/tweakpane": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/tweakpane/-/tweakpane-4.0.3.tgz", + "integrity": "sha512-BlcWOAe8oe4c+k9pmLBARGdWB6MVZMszayekkixQXTgkxTaYoTUpHpwVEp+3HkoamZkomodpbBf0CkguIHTgLg==", + "funding": { + "url": "https://github.com/sponsors/cocopon" + } + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -5891,7 +5924,6 @@ "version": "3.1.3", "resolved": "https://registry.npmjs.org/vt-pbf/-/vt-pbf-3.1.3.tgz", "integrity": "sha512-2LzDFzt0mZKZ9IpVF2r69G9bXaP2Q2sArJCmcCgvfTdCCZzSyz4aCLoQyUilu37Ll56tCblIZrXFIjNUpGIlmA==", - "peer": true, "dependencies": { "@mapbox/point-geometry": "0.1.0", "@mapbox/vector-tile": "^1.3.1", diff --git a/package.json b/package.json index c9bb6ca..aed456d 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "jalaliday": "^2.3.0", "jwt-decode": "^4.0.0", "lucide-react": "^0.365.0", + "mapbox-gl": "^3.3.0", "next": "14.1.4", "next-nprogress-bar": "^2.3.11", "next-themes": "^0.3.0", @@ -44,6 +45,7 @@ "zustand": "^4.5.2" }, "devDependencies": { + "@types/mapbox-gl": "^3.1.0", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", diff --git a/utils/CitizenReport.ts b/utils/CitizenReport.ts index 784d558..2092477 100644 --- a/utils/CitizenReport.ts +++ b/utils/CitizenReport.ts @@ -1,5 +1,5 @@ import axios from "axios"; -import { CookieValueTypes, getCookie } from "cookies-next"; +import { CookieValueTypes, getCookie } from "cookies-next"; axios.defaults.baseURL = process.env.NEXT_PUBLIC_BASE_URL_APP; // axios.defaults.baseURL = "https://shahrbinapi.shetabdahi.ir/"; @@ -10,23 +10,6 @@ axios.interceptors.request.use(function (config) { return config; }); -// Get Location -export async function getLocations() { - const data = await axios.get(`/api/CitizenReport/Locations?instanceId=1`, { - }); - return data.data; -} - -// ResendOtp -export async function resendOtp(payload: { otpToken: string | any}) { - const data = await axios.post( - `/api/Authenticate/ResendOtp`, - payload - ); - return data.data; -} - - // Get CitizenReport export async function getCitizenReport({ PageNumber = 1, @@ -35,9 +18,107 @@ export async function getCitizenReport({ }: { PageNumber?: number; PageSize?: number; - instanceId?:number; -}) { - const data = await axios.get(`/api/CitizenReport?instanceId=${instanceId}&PageNumber=${PageNumber}&PageSize=${PageSize}`, { - }); + instanceId?: number; +}) { + const data = await axios.get( + `/api/CitizenReport?instanceId=${instanceId}&PageNumber=${PageNumber}&PageSize=${PageSize}`, + {} + ); return data.data; } + +// Post CitizenReport +export async function postCitizenReport(payload: { + instanceId: number; + categoryId: number; + comments: string; + address: { + regionId: number; + latitude: number; + longitude: number; + detail: string; + }; + attachments: []; + isIdentityVisible: true; +}) { + const data = await axios.post(`api/api/CitizenReport`, payload); + return data.data; +} + + +// Get CitizenReport Nearest +export async function getCitizenReportNearest({ + PageNumber = 1, + PageSize = 10, + instanceId = 1, +}: { + PageNumber?: number; + PageSize?: number; + instanceId?: number; +}) { + const data = await axios.get( + `/api/CitizenReport/Nearest?instanceId=${instanceId}&PageNumber=${PageNumber}&PageSize=${PageSize}`, + {} + ); + return data.data; +} + + +// Get Location +export async function getLocations() { + const data = await axios.get(`/api/CitizenReport/Locations?instanceId=1`); + return data.data; +} + +// Get Location {ID} +export async function getSingleLocations(id: any) { + const data = await axios.get(`/api/CitizenReport/Locations/${id}`); + return data.data; +} + + +// Get CitizenReport Mine +export async function getCitizenReportMine({ + PageNumber = 1, + PageSize = 10, +}: { + PageNumber?: number; + PageSize?: number; +}) { + const data = await axios.get( + `/api/CitizenReport/Mine?PageNumber=${PageNumber}&PageSize=${PageSize}` + ); + return data.data; +} + +// Get CitizenReport Mine {Id} +export async function getSingleCitizenReportMine(id: string) { + const data = await axios.get(`/api/CitizenReport/Mine/${id}`); + return data.data; +} + + +// Put CitizenReport Like +export async function SetLike({ + id, + isLiked, +}: { + id: string; + isLiked: boolean; +}) { + const data = await axios.put(`/api/CitizenReport/Like/${id}?isLiked=${isLiked}`); + return data.data; +} + + +// Post CitizenReport Comment {id} +export async function postCitizenReportComment(id: string, comment: string) { + const data = await axios.post(`/api/CitizenReport/Comment/${id}`, { comment }); + return data.data; +} + +// Get CitizenReport Comment {id} +export async function getCitizenReportComment(id: string) { + const data = await axios.get(`/api/CitizenReport/Comments/${id}`); + return data.data; +} \ No newline at end of file diff --git a/utils/authenticateApi.ts b/utils/authenticateApi.ts index d048847..912f17a 100644 --- a/utils/authenticateApi.ts +++ b/utils/authenticateApi.ts @@ -31,6 +31,8 @@ axios.interceptors.response.use( const refreshToken = getCookie("Shahrbin_Refresh_Token"); //accessToken && refreshToken && !isRefreshing if (!isRefreshing) { + console.log("2222"); + isRefreshing = true; try { @@ -58,20 +60,6 @@ axios.interceptors.response.use( } ); - -export async function RefreshToken(payload: { token: any; refreshToken: any }) { - try { - const response = await axios.post("api/Authenticate/Refresh", payload); - setCookie("Shahrbin_Token", response.data.jwtToken); - setCookie("Shahrbin_Refresh_Token", response.data.refreshToken); - return response.data; - } catch (error) { - deleteCookie("Shahrbin_Token"); - deleteCookie("Shahrbin_Refresh_Token"); - window.location.href = "/"; - } -} - export async function revoke(payload: { refreshToken: string | CookieValueTypes; }) { @@ -83,6 +71,19 @@ export async function revoke(payload: { } +export async function RefreshToken(payload: { token: any; refreshToken: any }) { + try { + const response = await axios.post("api/Authenticate/Refresh", payload); + setCookie("Shahrbin_Token", response.data.jwtToken); + setCookie("Shahrbin_Refresh_Token", response.data.refreshToken); + return response.data; + } catch (error) { + deleteCookie("Shahrbin_Token"); + deleteCookie("Shahrbin_Refresh_Token"); + window.location.href = "/"; + } +} + export async function logisterCitizen(payload: { phoneNumber: string; captcha: {