Compare commits
4 Commits
2fc9cc9951
...
74246639e3
| Author | SHA1 | Date |
|---|---|---|
|
|
74246639e3 | |
|
|
13758eff56 | |
|
|
4075917927 | |
|
|
7e8e3b6b9f |
|
|
@ -0,0 +1,8 @@
|
|||
import ChangePhoneNumber from "@/components/ChangePhoneNumber";
|
||||
import React from "react";
|
||||
|
||||
function page() {
|
||||
return <ChangePhoneNumber />;
|
||||
}
|
||||
|
||||
export default page;
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
import Profile from "@/components/ui/Profile";
|
||||
import React from "react";
|
||||
|
||||
export default function page() {
|
||||
return <Profile />;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import ChangePhoneNumber from "@/components/ChangePhoneNumber";
|
||||
import React from "react";
|
||||
|
||||
function page() {
|
||||
return <ChangePhoneNumber />;
|
||||
}
|
||||
|
||||
export default page;
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
import Profile from "@/components/ui/Profile";
|
||||
import React from "react";
|
||||
|
||||
export default function page() {
|
||||
return <Profile />;
|
||||
}
|
||||
|
|
@ -42,8 +42,9 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
|||
import { useForm } from "react-hook-form";
|
||||
import * as z from "zod";
|
||||
import { Textarea } from "./ui/textarea";
|
||||
import { Check } from "lucide-react";
|
||||
import { Check, KeyRound } from "lucide-react";
|
||||
import { Progress } from "./ui/progress";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const MAX_FILE_SIZE = 5242880; // 5 MB
|
||||
// Edit Key Form
|
||||
|
|
@ -127,6 +128,10 @@ export default function AdminKeysManagement() {
|
|||
toast("عملیات شما با موفقیت انجام شد. ", {
|
||||
className: "!bg-green-500 !text-white",
|
||||
});
|
||||
} else if (res.failed > 0) {
|
||||
toast("مشکلی در تغییر کلید به وجود آمد.", {
|
||||
className: "!bg-red-500 !text-white",
|
||||
});
|
||||
}
|
||||
if (intervalRef.current !== null) {
|
||||
clearInterval(intervalRef.current);
|
||||
|
|
@ -269,8 +274,8 @@ export default function AdminKeysManagement() {
|
|||
useEffect(() => {
|
||||
const isChangingKey = localStorage.getItem("isChangingKey");
|
||||
if (isChangingKey) {
|
||||
setTimeout(() => {}, 10000);
|
||||
intervalRef.current = setInterval(refethKey, 10000);
|
||||
// setTimeout(() => {}, 1000);
|
||||
intervalRef.current = setInterval(refethKey, 2000);
|
||||
return () => {
|
||||
if (intervalRef.current !== null) {
|
||||
clearInterval(intervalRef.current);
|
||||
|
|
@ -319,7 +324,9 @@ export default function AdminKeysManagement() {
|
|||
<div className="w-[95vw] lg:w-[85vw] 3xl:w-[70vw] mt-8 max-sm:mt-16 pt-9 ">
|
||||
{polling && (
|
||||
<div className=" w-full md:w-1/2 mx-auto mt-2">
|
||||
<p className=" font-bold test-sm">درحال تغییر کلید ...</p>
|
||||
<p className=" font-bold test-sm">
|
||||
درحال تغییر کلید({Math.floor((done * 100) / total)}%) ...
|
||||
</p>
|
||||
<Progress className=" mt-5" value={(done * 100) / total} />
|
||||
</div>
|
||||
)}
|
||||
|
|
@ -389,11 +396,11 @@ export default function AdminKeysManagement() {
|
|||
render={({ field }) => (
|
||||
<FormItem className="w-full ">
|
||||
<FormLabel className="text-[#7C838A] text-sm font-medium ">
|
||||
کلید عمومی
|
||||
کلید خصوصی
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Textarea
|
||||
placeholder="کلید عمومی را وارد کنید"
|
||||
placeholder="کلید خصوصی را وارد نمایید."
|
||||
{...field}
|
||||
className="bg-white resize-none"
|
||||
dir="ltr"
|
||||
|
|
@ -443,13 +450,22 @@ export default function AdminKeysManagement() {
|
|||
return (
|
||||
<div
|
||||
key={item.id}
|
||||
className={`flex flex-col justify-center gap-2 w-full md:w-[31%] lg:w-[23%] h-28 px-5 rounded-md shadow-md items-start bg-[#F5F5F5]
|
||||
`}
|
||||
className={cn(
|
||||
`flex flex-col justify-center gap-2 w-full md:w-[31%] lg:w-[23%] h-28 px-5 rounded-md shadow-md items-start bg-[#F5F5F5]
|
||||
`,
|
||||
item?.isActive && " border-r-4 border-green-600"
|
||||
)}
|
||||
>
|
||||
<div className=" flex gap-2 items-center">
|
||||
<div className=" p-2 bg-blue rounded-lg">
|
||||
<KeyRound className=" text-white" />
|
||||
</div>
|
||||
<p className="text-sm font-normal leading-normal text-slate-500">
|
||||
عنوان کلید:{" "}
|
||||
{/* عنوان کلید:{" "} */}
|
||||
<span className=" text-slate-800">{item.title}</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* <p className="text-sm font-normal leading-normal text-slate-500">
|
||||
آیدی بازرس:{" "}
|
||||
<span className="self-end text-slate-800">
|
||||
|
|
|
|||
|
|
@ -126,6 +126,7 @@ export default function AdminNews() {
|
|||
const [imageNews, setImageNews] = useState("");
|
||||
const [page, setPage] = useState<any>(1);
|
||||
const [totalCount, setTotalCount] = useState<any>(0);
|
||||
const [totalPages, setTotalPages] = useState<any>(0);
|
||||
const [keyIdDel, setKeyIdDel] = useState("");
|
||||
|
||||
const [openAdd, setOpenAdd] = React.useState(false);
|
||||
|
|
@ -333,6 +334,7 @@ export default function AdminNews() {
|
|||
if (data1) {
|
||||
const headersData = JSON.parse(data1.headers["x-pagination"]);
|
||||
setTotalCount(headersData.TotalCount);
|
||||
setTotalPages(headersData.TotalPages);
|
||||
setPage(headersData.CurrentPage);
|
||||
}
|
||||
}, [data1]);
|
||||
|
|
@ -346,7 +348,7 @@ export default function AdminNews() {
|
|||
});
|
||||
};
|
||||
return (
|
||||
<div className="w-full min-h-[85vh] flex justify-center pb-4">
|
||||
<div className="w-full min-h-[85vh] flex justify-center max-lg:pb-20">
|
||||
<div className="w-[95vw] lg:w-[85vw] 3xl:w-[70vw] mt-8 max-sm:mt-16 pt-9 ">
|
||||
<div className="flex flex-row items-center justify-between w-full ">
|
||||
{/* 1 */}
|
||||
|
|
@ -789,6 +791,7 @@ export default function AdminNews() {
|
|||
</AlertDialog>
|
||||
{!isListLoading && (
|
||||
<Pagination
|
||||
TotalPages={totalPages}
|
||||
currentPage={page - 1}
|
||||
PageSize={5}
|
||||
countPage={totalCount}
|
||||
|
|
|
|||
|
|
@ -195,7 +195,6 @@ export default function AdminSlider() {
|
|||
});
|
||||
// Edit Submit
|
||||
|
||||
|
||||
// ............'Mutation' Change Slider Submit
|
||||
const ChangeSliderMutation = useMutation({
|
||||
mutationKey: ["ChangeSlider"],
|
||||
|
|
@ -252,7 +251,6 @@ const AddSliderMutation = useMutation({
|
|||
urlSlider: "",
|
||||
description: "",
|
||||
});
|
||||
|
||||
},
|
||||
onError: (err: any | string) => {
|
||||
toast(<>{err.response.data.detail}</>, {
|
||||
|
|
@ -283,7 +281,6 @@ function onSubmitEdit(data: EditSliderFormValues) {
|
|||
ChangeSliderMutation.mutate({ id: keyId, payload: formData });
|
||||
|
||||
refetch1();
|
||||
|
||||
}
|
||||
|
||||
function onSubmitAdd(data: AddSliderFormValues) {
|
||||
|
|
@ -337,7 +334,12 @@ const { resetField } = useForm();
|
|||
<p className="text-[#464646] text-base font-bold">
|
||||
افزودن اسلایدر
|
||||
</p>
|
||||
<AlertDialogCancel className="h-auto p-0 border-0" onClick={() => { resetFormAdd(); }}>
|
||||
<AlertDialogCancel
|
||||
className="h-auto p-0 border-0"
|
||||
onClick={() => {
|
||||
resetFormAdd();
|
||||
}}
|
||||
>
|
||||
<IoMdClose />
|
||||
</AlertDialogCancel>
|
||||
</AlertDialogTitle>
|
||||
|
|
@ -473,7 +475,12 @@ const { resetField } = useForm();
|
|||
>
|
||||
افزودن
|
||||
</Button>
|
||||
<AlertDialogCancel className="mt-0 text-white bg-blue rounded-xl" onClick={() => { resetFormAdd(); }}>
|
||||
<AlertDialogCancel
|
||||
className="mt-0 text-white bg-blue rounded-xl"
|
||||
onClick={() => {
|
||||
resetFormAdd();
|
||||
}}
|
||||
>
|
||||
بستن
|
||||
</AlertDialogCancel>
|
||||
</div>
|
||||
|
|
@ -646,27 +653,33 @@ const { resetField } = useForm();
|
|||
return (
|
||||
<div
|
||||
key={item.id}
|
||||
className={`flex flex-col justify-around gap-2 w-full lg:w-[49%] h-52 px-5 rounded-md shadow-md items-start bg-[#F5F5F5]
|
||||
className={`w-full lg:w-[48%] bg-[#F5F5F5] border rounded-lg flex flex-row shadow-md transition-all
|
||||
h-[20em] sm:h-[15em] max-sm:flex-col max-sm:gap-[3px]
|
||||
`}
|
||||
>
|
||||
<div className="w-1/2 h-full rounded-r-lg max-sm:h-1/2 max-md:w-1/3 max-sm:w-full">
|
||||
<Image
|
||||
alt="picture"
|
||||
src={`${process.env.NEXT_PUBLIC_BASE_URL_APP}${item?.image?.url}`}
|
||||
height={500}
|
||||
width={500}
|
||||
quality={100}
|
||||
className="w-full h-full rounded-r-lg bg-cover object-cover"
|
||||
/>
|
||||
</div>
|
||||
<div className="w-1/2 h-full flex flex-col p-3 justify-between max-md:justify-evenly max-md:w-2/3 max-sm:h-1/2 max-sm:w-full">
|
||||
<div>
|
||||
<p className="text-sm font-normal leading-normal text-slate-500">
|
||||
عنوان :<span className=" text-slate-800">{item.title}</span>
|
||||
عنوان :
|
||||
<span className=" text-slate-800">{item.title}</span>
|
||||
</p>
|
||||
<p className="text-sm font-normal leading-normal text-slate-500">
|
||||
توضیحات:
|
||||
<span className="self-end text-slate-800">
|
||||
<span className="self-end text-slate-800 line-clamp-4">
|
||||
{item.description}
|
||||
</span>
|
||||
</p>
|
||||
<Image
|
||||
alt="img"
|
||||
src={`${process.env.NEXT_PUBLIC_BASE_URL_APP}${item?.image?.url}`}
|
||||
width={100}
|
||||
height={100}
|
||||
quality={100}
|
||||
className="object-contain object-right w-full h-20 "
|
||||
/>
|
||||
|
||||
</div>
|
||||
{/* <p className="text-sm font-normal leading-normal text-slate-500">
|
||||
محتوا:
|
||||
<span className="self-end text-slate-800">
|
||||
|
|
@ -705,6 +718,7 @@ const { resetField } = useForm();
|
|||
</AlertDialogTrigger>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</AlertDialog>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,153 @@
|
|||
import React from "react";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { X } from "lucide-react";
|
||||
import { Button } from "./ui/button";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { z } from "zod";
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormDescription,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
} from "@/components/ui/form";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { changePassword } from "@/utils/authenticateApi";
|
||||
import { deleteCookie } from "cookies-next";
|
||||
import { toast } from "sonner";
|
||||
import { useRouter } from "next/navigation";
|
||||
export default function ChangePasswordDialog({
|
||||
data,
|
||||
open,
|
||||
setOpen,
|
||||
}: {
|
||||
data?: any;
|
||||
open: any;
|
||||
setOpen: (state: any) => any;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const ChangePasswordMutation = useMutation({
|
||||
mutationKey: ["ChangePassword"],
|
||||
mutationFn: changePassword,
|
||||
onSuccess: (res) => {
|
||||
deleteCookie("Sootzani_Admin_Token");
|
||||
localStorage.removeItem("privateKey");
|
||||
localStorage.removeItem("privatePassword");
|
||||
router.push("/");
|
||||
toast("رمز عبور شما با موفقیت تغییر یافت.", {
|
||||
className: "!bg-green-500 !text-white",
|
||||
});
|
||||
},
|
||||
onError: (err: any | string) => {
|
||||
toast(<>{err.response.data.detail}</>, {
|
||||
className: "!bg-red-500 !text-white",
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const FormSchema = z.object({
|
||||
oldPassword: z.string(),
|
||||
newPassword: z.string(),
|
||||
repeatedPassword: z.string(),
|
||||
});
|
||||
|
||||
const form = useForm<z.infer<typeof FormSchema>>({
|
||||
resolver: zodResolver(FormSchema),
|
||||
});
|
||||
|
||||
function onSubmit(data: z.infer<typeof FormSchema>) {
|
||||
if (data.newPassword !== data.repeatedPassword) {
|
||||
toast("رمز عبور شما با هم مطابقت ندارد.", {
|
||||
className: "!bg-red-500 !text-white",
|
||||
});
|
||||
return;
|
||||
}
|
||||
ChangePasswordMutation.mutate({
|
||||
oldPassword: data.oldPassword,
|
||||
newPassword: data.newPassword,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogContent>
|
||||
{" "}
|
||||
<Form {...form}>
|
||||
<form
|
||||
onSubmit={form.handleSubmit(onSubmit)}
|
||||
className="flex flex-col w-full mt-6 "
|
||||
>
|
||||
<DialogHeader>
|
||||
<DialogTitle>تغییر رمز عبور</DialogTitle>
|
||||
<DialogDescription>
|
||||
<div className="flex flex-col w-full my-6 ">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="oldPassword"
|
||||
render={({ field }) => (
|
||||
<FormItem className="w-full">
|
||||
<FormLabel className="text-[#7C838A] text-sm font-medium mt-7">
|
||||
رمز عبور فعلی
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="password" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="newPassword"
|
||||
render={({ field }) => (
|
||||
<FormItem className="w-full">
|
||||
<FormLabel className="text-[#7C838A] text-sm font-medium mt-7">
|
||||
رمز عبور جدید
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="password" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="repeatedPassword"
|
||||
render={({ field }) => (
|
||||
<FormItem className="w-full">
|
||||
<FormLabel className="text-[#7C838A] text-sm font-medium mt-7">
|
||||
تکرار رمز عبور
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="password" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogDescription></DialogDescription>
|
||||
<DialogFooter>
|
||||
<Button type="submit">تایید و ادامه</Button>
|
||||
</DialogFooter>{" "}
|
||||
</form>
|
||||
</Form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,129 @@
|
|||
"use client";
|
||||
import { putChangePhoneNumber } from "@/utils/authenticateApi";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import LoginIcon from "../public/img/login-icon.svg";
|
||||
import Image from "next/image";
|
||||
import OTPInput from "react-otp-input";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { deleteCookie } from "cookies-next";
|
||||
|
||||
export default function ChangePhoneNumber() {
|
||||
const [otp, setOtp] = useState("");
|
||||
const [otp2, setOtp2] = useState("");
|
||||
const [phoneNumber, setPhoneNumber] = useState<any>("");
|
||||
const [newPhoneNumber, setNewPhoneNumber] = useState<any>("");
|
||||
const space = "\xa0";
|
||||
const router = useRouter();
|
||||
const changePhoneNumberMutation = useMutation({
|
||||
mutationKey: ["putChangePhoneNumber"],
|
||||
mutationFn: putChangePhoneNumber,
|
||||
onSuccess: (res) => {
|
||||
deleteCookie("Sootzani_Admin_Token");
|
||||
localStorage.removeItem("privateKey");
|
||||
localStorage.removeItem("privatePassword");
|
||||
router.push("/");
|
||||
toast("شماره موبایل با موفقیت تغییر یافت.", {
|
||||
className: "!bg-green-500 !text-white",
|
||||
});
|
||||
},
|
||||
onError: (err: any | string) => {
|
||||
toast(<>{err.response.data.detail}</>, {
|
||||
className: "!bg-red-500 !text-white",
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (otp.length == 6 && otp2.length == 6) {
|
||||
const payload = {
|
||||
token1: localStorage.getItem("ph_token") as string,
|
||||
code1: otp,
|
||||
token2: localStorage.getItem("ph_newToken") as string,
|
||||
code2: otp2,
|
||||
};
|
||||
changePhoneNumberMutation.mutate(payload);
|
||||
}
|
||||
}, [otp,otp2]);
|
||||
|
||||
useEffect(() => {
|
||||
const phoneNumber = localStorage.getItem("ph_phoneNumber");
|
||||
const newPhoneNumber = localStorage.getItem("ph_newPhoneNumber");
|
||||
setPhoneNumber(phoneNumber);
|
||||
setNewPhoneNumber(newPhoneNumber);
|
||||
}, []);
|
||||
return (
|
||||
<div className="grid w-screen h-screen bg-gray-200 place-content-center">
|
||||
<div
|
||||
className="w-full sm:[20rem] md:[20rem] xl:w-[30rem] bg-white rounded-lg dark:border xl:p-0 dark:bg-gray-800 dark:border-gray-700 shadow-[0px_0px_15px_0px_#00000040]
|
||||
h-fit relative"
|
||||
>
|
||||
<div className="flex flex-col justify-center h-full p-10 space-y-3 md:space-y-4 md:py-10 md:px-12 lg:px-16">
|
||||
<Image alt="icon" src={LoginIcon} className="self-center w-1/3 " />
|
||||
<p className="text-lg font-bold leading-tight tracking-tight text-blue dark:text-white">
|
||||
کد شماره {phoneNumber}
|
||||
</p>
|
||||
<div className="w-full " dir="ltr">
|
||||
<OTPInput
|
||||
value={otp}
|
||||
onChange={setOtp}
|
||||
numInputs={6}
|
||||
renderSeparator={<span>{space}</span>}
|
||||
renderInput={(props, idx) => (
|
||||
<input autoFocus={idx == 0} pattern="[0-9]*" {...props} />
|
||||
)}
|
||||
containerStyle=" flex justify-center"
|
||||
inputStyle={` !w-10 rounded-md h-10 bg-[#F5F5F5] border border-blue/30 text-black `}
|
||||
/>
|
||||
</div>
|
||||
<p className="text-lg font-bold leading-tight tracking-tight text-blue dark:text-white">
|
||||
کد شماره {newPhoneNumber}
|
||||
</p>
|
||||
<div className="w-full " dir="ltr">
|
||||
<OTPInput
|
||||
value={otp2}
|
||||
onChange={setOtp2}
|
||||
numInputs={6}
|
||||
renderSeparator={<span>{space}</span>}
|
||||
renderInput={(props, idx) => (
|
||||
<input autoFocus={idx == 0} pattern="[0-9]*" {...props} />
|
||||
)}
|
||||
containerStyle=" flex justify-center"
|
||||
inputStyle={` !w-10 rounded-md h-10 bg-[#F5F5F5] border border-blue/30 text-black `}
|
||||
/>
|
||||
</div>
|
||||
<label className="text-center label">
|
||||
<span className="text-xs text-center text-blue/70 label-text">
|
||||
کد دریافت شده توسط پیامک را وارد نمایید.
|
||||
</span>
|
||||
</label>
|
||||
{/* <div className="flex justify-end w-full gap-2 mt-14">
|
||||
<Button
|
||||
disabled={verifyMutation.isPending}
|
||||
onClick={handelVerify}
|
||||
type="submit"
|
||||
className="w-1/2 p-2 text-white bg-blue hover:bg-blue/90 md:w-1/3 rounded-xl"
|
||||
>
|
||||
{verifyMutation.isPending ? (
|
||||
<div className="flex items-center justify-center gap-2">
|
||||
<Oval
|
||||
visible={true}
|
||||
height="20"
|
||||
width="20"
|
||||
color="#fff"
|
||||
ariaLabel="oval-loading"
|
||||
wrapperStyle={{}}
|
||||
wrapperClass=""
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
"تایید"
|
||||
)}
|
||||
</Button>
|
||||
</div> */}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,199 @@
|
|||
import React from "react";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { RefreshCcw, X } from "lucide-react";
|
||||
import { Button } from "./ui/button";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { z } from "zod";
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormDescription,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
} from "@/components/ui/form";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { getCaptcha } from "@/utils/commonApi";
|
||||
import { ThreeDots } from "react-loader-spinner";
|
||||
import Image from "next/image";
|
||||
import { postChangePhoneNumber } from "@/utils/authenticateApi";
|
||||
import { toast } from "sonner";
|
||||
import { useRouter } from "next/navigation";
|
||||
export default function ChangePhoneNumberDialog({
|
||||
data,
|
||||
open,
|
||||
setOpen,
|
||||
}: {
|
||||
data?: any;
|
||||
open: any;
|
||||
setOpen: (state: any) => any;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
|
||||
const {
|
||||
data: CaptchaData,
|
||||
isLoading,
|
||||
refetch,
|
||||
} = useQuery({
|
||||
queryKey: ["Captcha"],
|
||||
queryFn: () => getCaptcha(),
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
|
||||
const changePhoneNumberMutation = useMutation({
|
||||
mutationKey: ["postChangePhoneNumber"],
|
||||
mutationFn: postChangePhoneNumber,
|
||||
onSuccess: (res) => {
|
||||
localStorage.setItem("ph_token", res.token);
|
||||
localStorage.setItem("ph_newToken", res.newToken);
|
||||
localStorage.setItem("ph_phoneNumber", res.phoneNumber);
|
||||
localStorage.setItem("ph_newPhoneNumber", res.newPhoneNumber);
|
||||
const userRole = localStorage.getItem("userRole");
|
||||
if (userRole === "Admin") {
|
||||
router.push(`/UserPanel/AdminDashboard/ChangePhoneNumber`);
|
||||
} else {
|
||||
router.push(`/UserPanel/ControllerDashboard/ChangePhoneNumber`);
|
||||
}
|
||||
},
|
||||
onError: (err: any | string) => {
|
||||
refetch();
|
||||
toast(<>{err.response.data.detail}</>, {
|
||||
className: "!bg-red-500 !text-white",
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const FormSchema = z.object({
|
||||
phoneNumber: z.string().min(1, {
|
||||
message: "لطفا شماره موبایل را وارد نمایید.",
|
||||
}),
|
||||
captcha: z
|
||||
.string({ required_error: "لطفا کد امنیتی را وارد نمایید." })
|
||||
.length(5, { message: "لطفا کد امنیتی را به طور کامل وارد نمایید." }),
|
||||
});
|
||||
|
||||
const form = useForm<z.infer<typeof FormSchema>>({
|
||||
resolver: zodResolver(FormSchema),
|
||||
});
|
||||
|
||||
function onSubmit(data: z.infer<typeof FormSchema>) {
|
||||
const payload = {
|
||||
newPhoneNumber: data.phoneNumber,
|
||||
captcha: {
|
||||
key: CaptchaData?.headers["captcha-key"],
|
||||
value: data.captcha,
|
||||
},
|
||||
};
|
||||
changePhoneNumberMutation.mutate(payload);
|
||||
}
|
||||
|
||||
const srcForImage = CaptchaData
|
||||
? URL.createObjectURL(CaptchaData.data)
|
||||
: null;
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogContent>
|
||||
{" "}
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)}>
|
||||
<DialogHeader>
|
||||
<DialogTitle>تغییر شماره موبایل</DialogTitle>
|
||||
<DialogDescription>
|
||||
<div className="flex flex-col w-full my-6 ">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="phoneNumber"
|
||||
render={({ field }) => (
|
||||
<FormItem className="w-full">
|
||||
<FormLabel className="text-[#7C838A] text-sm font-medium mt-7">
|
||||
شماره موبایل جدید
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
onClick={() => setOpen(true)}
|
||||
type="text"
|
||||
className=" text-base"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<div className="flex items-center gap-3 mt-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="captcha"
|
||||
rules={{ required: true }}
|
||||
render={({ field }) => (
|
||||
<FormItem className="items-center flex-1 h-10 ">
|
||||
{/* <FormLabel className="text-[#7C838A] text-sm font-medium mt-7">
|
||||
رمز عبور
|
||||
</FormLabel> */}
|
||||
<FormControl>
|
||||
<Input
|
||||
className=" text-base"
|
||||
placeholder="کد امنیتی"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
{isLoading ? (
|
||||
<div className="flex justify-center text-center w-36">
|
||||
<ThreeDots
|
||||
visible={true}
|
||||
height="50"
|
||||
width="50"
|
||||
color="#003778"
|
||||
radius="9"
|
||||
ariaLabel="three-dots-loading"
|
||||
wrapperStyle={{}}
|
||||
wrapperClass=""
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex items-center justify-center gap-2 text-center ">
|
||||
<Image
|
||||
alt="icon"
|
||||
src={srcForImage as string}
|
||||
className="h-12 rounded-md shadow-md w-36"
|
||||
width={150}
|
||||
height={20}
|
||||
quality={100}
|
||||
/>
|
||||
<RefreshCcw
|
||||
className="cursor-pointer "
|
||||
onClick={() => refetch()}
|
||||
color="#003778"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogDescription></DialogDescription>
|
||||
<DialogFooter>
|
||||
<Button type="submit">تایید و ادامه</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</Form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ import { useMutation, useQuery } from "@tanstack/react-query";
|
|||
import { DoorOpen, LogOut } from "lucide-react";
|
||||
import { deleteCookie, getCookie } from "cookies-next";
|
||||
import useSignalR from "@/hooks/useSignalR";
|
||||
import ProfileDropDown from "./ProfileDropDown";
|
||||
|
||||
export default function NavbarPanel() {
|
||||
const [isOpen, setOpen] = useState(false);
|
||||
|
|
@ -141,17 +142,8 @@ export default function NavbarPanel() {
|
|||
</div>
|
||||
<div className="flex items-center gap-4 ">
|
||||
<h1 className="inline-block text-sm font-bold text-white bg-clip-text before:max-md:hidden max-md:text-xs max-md:font-medium">
|
||||
{data && (
|
||||
<>
|
||||
{role === "Admin"
|
||||
? `${data?.title ? data.title : data.username} (ادمین)`
|
||||
: `${data?.title ? data.title : data.username} (بازرس)`}
|
||||
</>
|
||||
)}
|
||||
<ProfileDropDown />
|
||||
</h1>
|
||||
<div className="p-1 rounded-md hover:bg-white/50">
|
||||
<LogOut onClick={logout} className="text-white cursor-pointer " />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,101 @@
|
|||
import React, { useEffect, useState } from "react";
|
||||
|
||||
import { CreditCard, LogOut, User, UserPlus, Users } from "lucide-react";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubContent,
|
||||
DropdownMenuSubTrigger,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { getProfile, revoke } from "@/utils/authenticateApi";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import Link from "next/link";
|
||||
import useToken from "@/store/useToken";
|
||||
import { deleteCookie, getCookie } from "cookies-next";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export default function ProfileDropDown() {
|
||||
const router = useRouter();
|
||||
const [role, setRole] = useState<any>(null);
|
||||
const {
|
||||
data: profileData,
|
||||
isLoading,
|
||||
refetch,
|
||||
} = useQuery({
|
||||
queryKey: ["Profile"],
|
||||
queryFn: () => getProfile(),
|
||||
});
|
||||
|
||||
const revokeMutation = useMutation({
|
||||
mutationFn: revoke,
|
||||
onSuccess: (res) => {},
|
||||
onError: (err: any | string) => {},
|
||||
});
|
||||
|
||||
const logout = () => {
|
||||
revokeMutation.mutate({
|
||||
refreshToken: getCookie("Sootzani_Admin_Refresh_Token"),
|
||||
});
|
||||
deleteCookie("Sootzani_Admin_Token");
|
||||
localStorage.removeItem("privateKey");
|
||||
localStorage.removeItem("privatePassword");
|
||||
router.push("/");
|
||||
};
|
||||
useEffect(() => {
|
||||
const userRole = localStorage.getItem("Sootzani_Role");
|
||||
if (userRole == "Admin") {
|
||||
setRole("AdminDashboard");
|
||||
} else {
|
||||
setRole("ControllerDashboard");
|
||||
}
|
||||
}, []);
|
||||
|
||||
const saveToken = useToken((state) => state.saveToken);
|
||||
return (
|
||||
<DropdownMenu dir="rtl">
|
||||
<DropdownMenuTrigger
|
||||
className=" max-sm:-mr-8 max-sm:text-xs w-12"
|
||||
asChild
|
||||
>
|
||||
<Button
|
||||
// variant="outline"
|
||||
className=" truncate bg-white text-blue hover:bg-white w-32 flex justify-center items-center gap-2"
|
||||
>
|
||||
<User className=" w-5 h-5" />
|
||||
{/* {profileData?.title ? profileData?.title : profileData?.userName} */}
|
||||
<p className=" truncate self-end">
|
||||
{" "}
|
||||
{profileData?.firstName || profileData?.lastName
|
||||
? profileData?.firstName + " " + profileData?.lastName
|
||||
: profileData?.userName}
|
||||
</p>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="w-56 sm:ml-10">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem
|
||||
onClick={() => router.push(`/UserPanel/${role}/Profile`)}
|
||||
>
|
||||
<User className="w-4 h-4 ml-2" />
|
||||
<span>پروفایل</span>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onClick={logout}>
|
||||
<LogOut className="w-4 h-4 ml-2" />
|
||||
<span>خروج</span>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,202 @@
|
|||
"use client";
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useForm } from "react-hook-form";
|
||||
import * as z from "zod";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormDescription,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
} from "@/components/ui/form";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import Link from "next/link";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { editProfile, getProfile } from "@/utils/authenticateApi";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { toast } from "sonner";
|
||||
import { Oval } from "react-loader-spinner";
|
||||
import ChangePhoneNumberDialog from "../ChangePhoneNumberDialog";
|
||||
import ChangePasswordDialog from "../ChangePasswordDialog";
|
||||
|
||||
const FormSchema = z.object({
|
||||
firstName: z.string().min(1, {
|
||||
message: "لطفا نام خود را وارد نمایید.",
|
||||
}),
|
||||
lastName: z.string().min(1, {
|
||||
message: "لطفا نام خانوادگی خود را وارد نمایید.",
|
||||
}),
|
||||
phoneNumber: z.string().optional(),
|
||||
});
|
||||
|
||||
export default function Profile() {
|
||||
const router = useRouter();
|
||||
const [open, setOpen] = useState<boolean>(false);
|
||||
const [open2, setOpen2] = useState<boolean>(false);
|
||||
const {
|
||||
data: profileData,
|
||||
isLoading,
|
||||
refetch,
|
||||
} = useQuery({
|
||||
queryKey: ["Profile"],
|
||||
queryFn: () => getProfile(),
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
|
||||
const editProfileMutation = useMutation({
|
||||
mutationKey: ["editProfile"],
|
||||
mutationFn: editProfile,
|
||||
onSuccess: (res) => {
|
||||
refetch();
|
||||
toast("پروفایل شما با موفقیت ویرایش شد.", {
|
||||
className: "!bg-green-500 !text-white",
|
||||
});
|
||||
router.push("/");
|
||||
},
|
||||
onError: (err: any | string) => {
|
||||
toast(<>{err.response.data.detail}</>, {
|
||||
className: "!bg-red-500 !text-white",
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const form = useForm<z.infer<typeof FormSchema>>({
|
||||
resolver: zodResolver(FormSchema),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (profileData) {
|
||||
form.setValue("firstName", profileData.firstName);
|
||||
form.setValue("lastName", profileData.lastName);
|
||||
form.setValue("phoneNumber", profileData.phoneNumber);
|
||||
}
|
||||
}, [profileData]);
|
||||
|
||||
function onSubmit(data: z.infer<typeof FormSchema>) {
|
||||
const payload = data;
|
||||
editProfileMutation.mutate(payload);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className=" w-full mx-auto mt-20 h-full pt-12 md:w-2/3 xl:w-1/2 p-8">
|
||||
<div className="flex flex-col justify-center h-full space-y-4 md:space-y-4">
|
||||
<h2 className=" w-full font-bold">اطلاعات هویتی</h2>
|
||||
{profileData && (
|
||||
<Form {...form}>
|
||||
<form
|
||||
onSubmit={form.handleSubmit(onSubmit)}
|
||||
className="flex flex-col w-full mt-6 "
|
||||
>
|
||||
<div className="flex flex-row flex-wrap justify-between border p-4 rounded-md">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="firstName"
|
||||
render={({ field }) => (
|
||||
<FormItem className="w-full sm:w-[48%]">
|
||||
<FormLabel className="text-[#7C838A] text-sm font-medium">
|
||||
نام
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
placeholder="نام خود را وارد نمایید"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="lastName"
|
||||
render={({ field }) => (
|
||||
<FormItem className="w-full sm:w-[48%] ">
|
||||
<FormLabel className="text-[#7C838A] text-sm font-medium">
|
||||
نام خانوادگی
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
placeholder="نام خانوادگی خود را وارد نمایید"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<div className="flex justify-end w-full gap-2 mt-8">
|
||||
<Button
|
||||
disabled={editProfileMutation.isPending}
|
||||
type="submit"
|
||||
className="w-32 p-2 text-white transition bg-blue hover:bg-blue/90 rounded-xl max-sm:text-xs"
|
||||
>
|
||||
{editProfileMutation.isPending ? (
|
||||
<div className="flex items-center justify-center gap-2">
|
||||
<Oval
|
||||
visible={true}
|
||||
height="20"
|
||||
width="20"
|
||||
color="#fff"
|
||||
ariaLabel="oval-loading"
|
||||
wrapperStyle={{}}
|
||||
wrapperClass=""
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
"ذخیره"
|
||||
)}
|
||||
{/* ورود */}
|
||||
</Button>
|
||||
</div>{" "}
|
||||
</div>
|
||||
<h2 className=" w-full font-bold mt-5 mb-2">اطلاعات ورود</h2>
|
||||
<div className=" border p-4 flex max-lg:flex-col justify-between rounded-md items-center">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="phoneNumber"
|
||||
render={({ field }) => (
|
||||
<FormItem className="w-full sm:w-[48%]">
|
||||
<FormLabel className="text-[#7C838A] text-sm font-medium mt-7">
|
||||
شماره موبایل
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="text" {...field} readOnly />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<div className="flex gap-2 max-md:justify-center max-md:mt-6 max-md:w-full">
|
||||
<Button
|
||||
type="button"
|
||||
disabled={editProfileMutation.isPending}
|
||||
onClick={() => setOpen(true)}
|
||||
className="max-sm:w-1/2 w-32 p-2 max-sm:text-xs text-white transition bg-blue hover:bg-blue/90 rounded-xl"
|
||||
>
|
||||
تغییر شماره موبایل
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={editProfileMutation.isPending}
|
||||
onClick={() => setOpen2(true)}
|
||||
className="max-sm:w-1/2 w-32 p-2 text-white transition bg-blue hover:bg-blue/90 rounded-xl max-sm:text-xs"
|
||||
>
|
||||
تغییر رمز عبور
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</Form>
|
||||
)}
|
||||
</div>
|
||||
<ChangePhoneNumberDialog open={open} setOpen={setOpen} />
|
||||
<ChangePasswordDialog open={open2} setOpen={setOpen2} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ const buttonVariants = cva(
|
|||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
||||
default: "bg-blue text-primary-foreground hover:bg-blue/90",
|
||||
destructive:
|
||||
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
||||
outline:
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ export function convertFullTime(date: string) {
|
|||
const convertedDate = dayjs(date + "Z")
|
||||
.calendar("jalali")
|
||||
.locale("fa")
|
||||
.format(" HH:mm:ss - YYYY/M/D");
|
||||
.format(" HH:mm - YYYY/M/D");
|
||||
return convertedDate;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "sootzani",
|
||||
"version": "0.2.15",
|
||||
"version": "0.2.18",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "sootzani",
|
||||
"version": "0.2.15",
|
||||
"version": "0.2.18",
|
||||
"dependencies": {
|
||||
"@hookform/resolvers": "^3.3.2",
|
||||
"@microsoft/signalr": "^8.0.0",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "sootzani",
|
||||
"version": "0.2.15",
|
||||
"version": "0.2.18",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ export async function UpdateWebContents({
|
|||
// .....News.................................................
|
||||
export async function GetAllNews({
|
||||
PageNumber = 1,
|
||||
PageSize = 6,
|
||||
PageSize = 4,
|
||||
}: {
|
||||
PageNumber?: number;
|
||||
PageSize?: number;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,12 @@ axios.interceptors.response.use(
|
|||
},
|
||||
async function (error) {
|
||||
const originalRequest = error.config;
|
||||
|
||||
if (error.response.status === 403) {
|
||||
window.location.href = "/";
|
||||
deleteCookie("Sootzani_Admin_Token");
|
||||
deleteCookie("Sootzani_Admin_Refresh_Token");
|
||||
localStorage.removeItem("privateKey");
|
||||
}
|
||||
if (error.response.status === 401) {
|
||||
if (!originalRequest._retry) {
|
||||
originalRequest._retry = true;
|
||||
|
|
@ -91,6 +96,27 @@ export async function verifyCitizen(payload: {
|
|||
return data.data;
|
||||
}
|
||||
|
||||
export async function postChangePhoneNumber(payload: {
|
||||
newPhoneNumber: string;
|
||||
captcha: {
|
||||
key: string;
|
||||
value: string;
|
||||
};
|
||||
}) {
|
||||
const data = await axios.post("api/Authenticate/PhoneNumber", payload);
|
||||
return data.data;
|
||||
}
|
||||
|
||||
export async function putChangePhoneNumber(payload: {
|
||||
token1: string;
|
||||
code1: string | null;
|
||||
token2: string;
|
||||
code2: string | null;
|
||||
}) {
|
||||
const data = await axios.put("api/Authenticate/PhoneNumber", payload);
|
||||
return data.data;
|
||||
}
|
||||
|
||||
export async function changePassword(payload: {
|
||||
oldPassword: string;
|
||||
newPassword: string;
|
||||
|
|
@ -107,9 +133,9 @@ export async function getProfile() {
|
|||
export async function editProfile(payload: {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
nationalId: string;
|
||||
phoneNumber2: string;
|
||||
title: string;
|
||||
nationalId?: string;
|
||||
phoneNumber2?: string;
|
||||
title?: string;
|
||||
}) {
|
||||
const data = await axios.put("api/Authenticate/Profile", payload);
|
||||
return data.data;
|
||||
|
|
|
|||
Loading…
Reference in New Issue