From eecb99ee5c09594c3eeca74e40f173d813b4f112 Mon Sep 17 00:00:00 2001 From: YasamanKahdooei Date: Sun, 12 May 2024 15:20:52 +0330 Subject: [PATCH] Added part of Map , RecentRequestCard --- .env | 14 +- app/User/MyRequest/page.tsx | 2 +- components/RecentRequest/OnMapRequests.tsx | 97 +++++++------- components/RecentRequest/RecentRequests.tsx | 51 ++++---- components/RecentRequest/RequestList.tsx | 4 +- components/Requests/RequestCard.tsx | 138 +++++++++++++------- components/Requests/RequestStatus.tsx | 8 +- lib/utils.ts | 21 +++ next.config.mjs | 4 +- package-lock.json | 12 ++ package.json | 2 + utils/CitizenCommon.ts | 12 ++ utils/CitizenReport.ts | 27 +++- utils/apiInstance.ts | 7 + utils/authenticateApi.ts | 5 + 15 files changed, 272 insertions(+), 132 deletions(-) create mode 100644 utils/CitizenCommon.ts diff --git a/.env b/.env index 5f40f89..65c05ec 100644 --- a/.env +++ b/.env @@ -1,10 +1,10 @@ NEXT_PUBLIC_BASE_URL_APP="https://shahrbinapi.shetabdahi.ir/" -REACT_APP_APP_CITY= yazd -REACT_APP_MUNICIPALITY_LOGO= Yazd-Municipality.png -REACT_APP_LOGO= shahrbin_yazd.png -REACT_APP_LATITUDE= 31.8974 -REACT_APP_LONGITUDE= 54.3569 -REACT_APP_PMI_TOKEN=p18879615a54484eb98d403da218956ecaa2740c42 -REACT_APP_MY_GOV_LINK= https://my.yazd.ir/api/oauth/authorize/?response_type=code&client_id=jwjOjhnZzct0AzNSacV0XYOvxOKXrLfnumM8hYPN&scope=read +NEXT_PUBLIC_APP_CITY= yazd +NEXT_PUBLIC_MUNICIPALITY_LOGO= Yazd-Municipality.png +NEXT_PUBLIC_LOGO= shahrbin_yazd.png +NEXT_PUBLIC_LATITUDE= 31.8974 +NEXT_PUBLIC_LONGITUDE= 54.3569 +NEXT_PUBLIC_PMI_TOKEN=p18879615a54484eb98d403da218956ecaa2740c42 +NEXT_PUBLIC_MY_GOV_LINK= https://my.yazd.ir/api/oauth/authorize/?response_type=code&client_id=jwjOjhnZzct0AzNSacV0XYOvxOKXrLfnumM8hYPN&scope=read NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN=pk.eyJ1IjoiZmFicmljOCIsImEiOiJjaWc5aTV1ZzUwMDJwdzJrb2w0dXRmc2d0In0.p6GGlfyV-WksaDV_KdN27A diff --git a/app/User/MyRequest/page.tsx b/app/User/MyRequest/page.tsx index 7d0a5ca..9625b94 100644 --- a/app/User/MyRequest/page.tsx +++ b/app/User/MyRequest/page.tsx @@ -5,7 +5,7 @@ import React from "react"; export default function page() { return (
- + {/* */}
); diff --git a/components/RecentRequest/OnMapRequests.tsx b/components/RecentRequest/OnMapRequests.tsx index 7359d03..148a3b1 100644 --- a/components/RecentRequest/OnMapRequests.tsx +++ b/components/RecentRequest/OnMapRequests.tsx @@ -1,5 +1,5 @@ "use client"; -import React, { useRef, useState } from "react"; +import React, { useEffect, useRef, useState } from "react"; import { getLocations } from "@/utils/CitizenReport"; import { useQuery } from "@tanstack/react-query"; import { ThreeDots } from "react-loader-spinner"; @@ -18,17 +18,27 @@ const MapContainer = ReactMapboxGl({ }); const OnMapRequests = () => { - const [selected, setSelected] = useState(null); + const [selected, setSelected] = 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, + }; + }, [citizenInstance]); // refs const detailsRef = useRef(null); const wrappersRef = useRef(null); - const defaultCoords = { - // latitude: instances[0].latitude, - // longitude: instances[0].longitude, - }; - // hooks // const [detailsClicked, setDetailsClicked] = useClick({ // element: detailsRef, @@ -59,23 +69,28 @@ const OnMapRequests = () => { } = useQuery({ queryKey: ["Locations"], queryFn: () => getLocations(), - // refetchOnWindowFocus: false, + refetchOnWindowFocus: false, }); - if (isSuccess) { - console.log(LocationData?.locations[0].locations); - const fetchedContent = LocationData?.locations[0].locations; - console.log(fetchedContent); - } + 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 ( - <> +
{isLoading ? ( -
+
{ // store.instance?.longitude || defaultCoords.longitude, // store.instance?.latitude || defaultCoords.latitude, // ]} - center={[54.3683, 32.4279]} + zoom={[10]} + center={[31.887935423191124, 54.355335268625275]} containerStyle={{ height: "100%", width: "100%", borderRadius: 20 }} - style={`https://api.parsimap.ir/styles/parsimap-streets-v11?key=${process.env.REACT_APP_PMI_TOKEN}`} + style={`https://api.parsimap.ir/styles/parsimap-streets-v11?key=${process.env.NEXT_PUBLIC_PMI_TOKEN}`} // onClick={onMapClicked} > - {/* {LocationData?.map((d) => ( - - showDetails(d)} /> - - ))} */} - {LocationData?.map(() => ( - - showDetails()} /> + {locations?.map((d: any) => ( + + + {/* showDetails(d)} /> */} ))} -
- {/* {selected && } */} + {selected && }
-
+
*/} - - // )} {isError &&

Map Failed

} - +
); }; diff --git a/components/RecentRequest/RecentRequests.tsx b/components/RecentRequest/RecentRequests.tsx index d872f56..d906649 100644 --- a/components/RecentRequest/RecentRequests.tsx +++ b/components/RecentRequest/RecentRequests.tsx @@ -1,40 +1,41 @@ "use client"; -import React, { useEffect } from "react"; +import React, { useEffect, useState } from "react"; import OnMapRequests from "./OnMapRequests"; import AllRequests from "./AllRequests"; import NearestRequests from "./NearestRequests"; import { TabRequests } from "./TabRequests"; +import { useQuery } from "@tanstack/react-query"; +import { getInstances } from "@/utils/CitizenCommon"; // import UserContainer from "../User/UserContainer"; // import { useRouter } from "next/navigation"; -// import { useMutation } from "@tanstack/react-query"; -// import { revoke } from "@/utils/authenticateApi"; +// import { useMutation } from "@tanstack/react-query"; // import { deleteCookie, getCookie } from "cookies-next"; function RecentRequests() { + const [citizenInstance, setCitizenInstance] = useState(null); + // const router = useRouter(); + const { + data: instancesData, + isLoading, + isError, + isSuccess, + refetch, + } = useQuery({ + queryKey: ["Instances"], + queryFn: () => getInstances(), + refetchOnWindowFocus: false, + }); - // const revokeMutation = useMutation({ - // mutationFn: revoke, - // onSuccess: (res) => {}, - // onError: (err: any | string) => {}, - // }); - - // const logout = () => { - // revokeMutation.mutate({ - // refreshToken: getCookie("Shahrbin_Refresh_Token"), - // }); - // // saveToken(false); - // deleteCookie("Shahrbin_Refresh_Token"); - // deleteCookie("Shahrbin_Token"); - // router.push("/"); - // }; - - // useEffect(() => { - // if (!getCookie("Shahrbin_Token")) { - // logout(); - // } - // }, []); - + useEffect(() => { + if (instancesData) { + console.log(instancesData); + console.log(instancesData?.data); + console.log(instancesData?.data[0]); + localStorage.setItem("SH_CT_INSTANCE",JSON.stringify(instancesData?.data[0])); + } + }, [isSuccess]); + return (
{/* Right */} diff --git a/components/RecentRequest/RequestList.tsx b/components/RecentRequest/RequestList.tsx index b56bd11..5ead111 100644 --- a/components/RecentRequest/RequestList.tsx +++ b/components/RecentRequest/RequestList.tsx @@ -3,8 +3,8 @@ import RequestCard from "../Requests/RequestCard"; const RequestList = () => { return ( -
- +
+
); }; diff --git a/components/Requests/RequestCard.tsx b/components/Requests/RequestCard.tsx index efd4857..bd1d5ee 100644 --- a/components/Requests/RequestCard.tsx +++ b/components/Requests/RequestCard.tsx @@ -1,5 +1,6 @@ +"use client"; import Image from "next/image"; -import React from "react"; +import React, { use, useEffect, useState } from "react"; import img1 from "@/assets/images/no-image.jpeg"; import RequestStatus from "./RequestStatus"; import { MdLocationOn } from "react-icons/md"; @@ -8,59 +9,100 @@ import RequestViolation from "./RequestViolation"; import RequestLike from "./RequestLike"; import RequestComments from "./RequestComments"; import Link from "next/link"; +import { useQuery } from "@tanstack/react-query"; +import { getCitizenReport } from "@/utils/CitizenReport"; +import { convertFullTime } from "@/lib/utils"; + +interface RequestCardProps { + isSelfRequest?: boolean; +} + +const RequestCard: React.FC = ({ isSelfRequest = false }) => { + const [reportData, setReportData] = useState(null); + const [haveImage, sethaveImage] = useState(null); + const { data, isLoading, isError, isSuccess, refetch } = useQuery({ + queryKey: ["CitizenReport"], + queryFn: () => + getCitizenReport({ PageNumber: 1, PageSize: 10, instanceId: 1 }), + refetchOnWindowFocus: false, + }); + + useEffect(() => { + if (data) { + console.log(data); + console.log(data.data); + console.log(data.data[0]); + setReportData(data.data); + } + }, [data]); -const RequestCard = () => { return ( - -
- 11 -
+
+ {reportData?.map((item: any) => { + return ( + +
+ 0 + ? `${process.env.NEXT_PUBLIC_BASE_URL_APP}${item.medias[0].url3}` + : img1 + } + alt="picture" + quality={100} + height={100} + width={100} + className="w-full h-full rounded-md object-contain" + /> +
-
- {/* 1 requestCardInfoRow */} -
-

عنوان دسته بندی

- -
+
+ {/* 1 requestCardInfoRow */} +
+

+ {item.categoryTitle} +

+ +
- {/* 2 */} -
-
- -

م. آزادی، بل فرخی

-
-
+ {/* 2 */} +
+
+ +

{item.addressDetail}

+
+
- {/* 3 */} -
-
- کد رهگیری: - 21221212121 -
-
- jul 28 2024 11:20 -
-
+ {/* 3 */} +
+
+ کد رهگیری: + {item.trackingNumber} +
+
+ {convertFullTime(item.sent)} +
+
- {/* 4 */} -
- -
- - - -
-
-
- + {/* 4 */} +
+ +
+ + + +
+
+
+ + ); + })} +
); }; diff --git a/components/Requests/RequestStatus.tsx b/components/Requests/RequestStatus.tsx index e937f75..d45c362 100644 --- a/components/Requests/RequestStatus.tsx +++ b/components/Requests/RequestStatus.tsx @@ -1,10 +1,14 @@ import React from "react"; -const RequestStatus = () => { +interface RequestStatusProps { + lastStatus?: String; +} + +const RequestStatus: React.FC = ({ lastStatus }) => { return ( <> - آخرین وضعیت + {lastStatus} ); diff --git a/lib/utils.ts b/lib/utils.ts index d084cca..4da7a76 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -1,6 +1,27 @@ import { type ClassValue, clsx } from "clsx" import { twMerge } from "tailwind-merge" +import dayjs from "dayjs"; +import utc from "dayjs/plugin/utc"; +import jalaliday from "jalaliday"; +dayjs.extend(jalaliday); +dayjs.extend(utc); export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)) } + +export function convertDate(date: string) { + const convertedDate = dayjs(date + "Z") + .calendar("jalali") + .locale("fa") + .format("YYYY/M/DD"); + return convertedDate; +} + +export function convertFullTime(date: string) { + const convertedDate = dayjs(date + "Z") + .calendar("jalali") + .locale("fa") + .format(" HH:mm ساعت YYYY/MM/DD"); + return convertedDate; +} \ No newline at end of file diff --git a/next.config.mjs b/next.config.mjs index 4678774..279030c 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,4 +1,6 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {}; +const nextConfig = { images: { + domains: ["shahrbinapi.shetabdahi.ir"], + },}; export default nextConfig; diff --git a/package-lock.json b/package-lock.json index c0ad11d..24af450 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,9 @@ "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", "cookies-next": "^4.1.1", + "dayjs": "^1.11.11", "framer-motion": "^11.1.7", + "jalaliday": "^2.3.0", "jwt-decode": "^4.0.0", "lucide-react": "^0.365.0", "next": "14.1.4", @@ -2006,6 +2008,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/dayjs": { + "version": "1.11.11", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.11.tgz", + "integrity": "sha512-okzr3f11N6WuqYtZSvm+F776mB41wRZMhKP+hc34YdW+KmtYYK9iqvHSwo2k9FEH3fhGXvOPV6yz2IcSrfRUDg==" + }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -3774,6 +3781,11 @@ "@pkgjs/parseargs": "^0.11.0" } }, + "node_modules/jalaliday": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/jalaliday/-/jalaliday-2.3.0.tgz", + "integrity": "sha512-B/m3TqsRrTFED/HBDqON6rPKe0MpoLxNICZ5uZeZ/scHJUHKQNr1n+wdZSj8MxrY1Bmo05gllZeNEw4beXd2oQ==" + }, "node_modules/jiti": { "version": "1.21.0", "resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.0.tgz", diff --git a/package.json b/package.json index c4b0e56..c9bb6ca 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,9 @@ "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", "cookies-next": "^4.1.1", + "dayjs": "^1.11.11", "framer-motion": "^11.1.7", + "jalaliday": "^2.3.0", "jwt-decode": "^4.0.0", "lucide-react": "^0.365.0", "next": "14.1.4", diff --git a/utils/CitizenCommon.ts b/utils/CitizenCommon.ts new file mode 100644 index 0000000..631c205 --- /dev/null +++ b/utils/CitizenCommon.ts @@ -0,0 +1,12 @@ +import axios from "axios"; +axios.defaults.baseURL = process.env.NEXT_PUBLIC_BASE_URL_APP; + +// Get Instances +export async function getInstances() { + const data = await axios.get(`/api/CitizenCommon/ShahrbinInstances`, { + + }); + console.log(data); + + return data.data; +} \ No newline at end of file diff --git a/utils/CitizenReport.ts b/utils/CitizenReport.ts index 69af62c..784d558 100644 --- a/utils/CitizenReport.ts +++ b/utils/CitizenReport.ts @@ -1,16 +1,23 @@ import axios from "axios"; -import { CookieValueTypes } 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/"; +axios.interceptors.request.use(function (config) { + const token = getCookie("Shahrbin_Token"); + config.headers.Authorization = token ? `Bearer ${token}` : ""; + return config; +}); + // Get Location export async function getLocations() { - const data = await axios.get(`/api/CitizenReport/Locations`, { + 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`, @@ -18,3 +25,19 @@ export async function resendOtp(payload: { otpToken: string | any}) { ); return data.data; } + + +// Get CitizenReport +export async function getCitizenReport({ + PageNumber = 1, + PageSize = 10, + instanceId = 1, +}: { + PageNumber?: number; + PageSize?: number; + instanceId?:number; +}) { + const data = await axios.get(`/api/CitizenReport?instanceId=${instanceId}&PageNumber=${PageNumber}&PageSize=${PageSize}`, { + }); + return data.data; +} diff --git a/utils/apiInstance.ts b/utils/apiInstance.ts index 7028c1f..f424304 100644 --- a/utils/apiInstance.ts +++ b/utils/apiInstance.ts @@ -1,8 +1,15 @@ import axios from "axios"; +import { getCookie } from "cookies-next"; import { toast } from "sonner"; const api = axios.create({ baseURL: "https://shahrbinapi.shetabdahi.ir/" }); +axios.interceptors.request.use(function (config) { + const token = getCookie("Shahrbin_Token"); + config.headers.Authorization = token ? `Bearer ${token}` : ""; + return config; +}); + api.interceptors.response.use( function (response) { console.log(response); diff --git a/utils/authenticateApi.ts b/utils/authenticateApi.ts index acc60eb..d048847 100644 --- a/utils/authenticateApi.ts +++ b/utils/authenticateApi.ts @@ -10,6 +10,11 @@ const instance = { id: 1 }; axios.defaults.baseURL = process.env.NEXT_PUBLIC_BASE_URL_APP; let isRefreshing = false; +axios.interceptors.request.use(function (config) { + const token = getCookie("Shahrbin_Token"); + config.headers.Authorization = token ? `Bearer ${token}` : ""; + return config; +}); axios.interceptors.response.use( (response) => {