+
);
};
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 (
-
-
-
-
+
+ {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) => {