173 lines
5.1 KiB
TypeScript
173 lines
5.1 KiB
TypeScript
"use client";
|
||
import React from "react";
|
||
|
||
import { zodResolver } from "@hookform/resolvers/zod";
|
||
import { useForm } from "react-hook-form";
|
||
import * as z from "zod";
|
||
import { useRouter } from "next/navigation";
|
||
import { useMutation } from "@tanstack/react-query";
|
||
|
||
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 { toast } from "@/components/ui/use-toast";
|
||
import { Textarea } from "@/components/ui/textarea";
|
||
|
||
import Image from "next/image";
|
||
import Link from "next/link";
|
||
import FollowResult from "./FollowResult";
|
||
import { postComplaintTracking } from "@/utils/citizenApi";
|
||
|
||
const FormSchema = z.object({
|
||
trackingNumber: z.string().min(2, {
|
||
message: "trackingNumber must be at least 2 characters.",
|
||
}),
|
||
password: z.string().min(4, {
|
||
message: "Password must be at least 4 characters.",
|
||
}),
|
||
});
|
||
|
||
export default function FollowUp() {
|
||
const router = useRouter();
|
||
|
||
const complaintTrackingMutation = useMutation({
|
||
mutationKey: ["complaintTracking"],
|
||
mutationFn: postComplaintTracking,
|
||
|
||
onSuccess: (res) => {
|
||
const result = res;
|
||
console.log(res);
|
||
console.log(result);
|
||
|
||
// alert("Success");
|
||
console.log("Success FollowUp");
|
||
|
||
// router.push("/FollowResult");
|
||
router.push("/FollowResult", {data: JSON.stringify( result ) });
|
||
|
||
// router.push(
|
||
// "/FollowResult",
|
||
// {
|
||
// data: JSON.stringify(result),
|
||
// },
|
||
// );
|
||
|
||
// router.push({
|
||
// pathname : '/FollowResult',
|
||
// query : {
|
||
// data: JSON.stringify( result ) ;
|
||
// },
|
||
// });
|
||
|
||
// return (res)
|
||
},
|
||
onError: (error) => {
|
||
console.log(error);
|
||
console.log(error?.message);
|
||
},
|
||
});
|
||
|
||
const form = useForm<z.infer<typeof FormSchema>>({
|
||
resolver: zodResolver(FormSchema),
|
||
defaultValues: {
|
||
trackingNumber: "",
|
||
password: "",
|
||
},
|
||
});
|
||
|
||
function onSubmit(data: z.infer<typeof FormSchema>) {
|
||
toast({
|
||
title: "You submitted the following values:",
|
||
description: (
|
||
<pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4 pt-12">
|
||
<code className="text-white">{JSON.stringify(data, null, 2)}</code>
|
||
</pre>
|
||
),
|
||
});
|
||
|
||
console.log(data);
|
||
|
||
localStorage.setItem("trackingNumber2", data.trackingNumber);
|
||
localStorage.setItem("password2", data.password);
|
||
|
||
complaintTrackingMutation.mutate({
|
||
Data: { trackingNumber: data.trackingNumber, password: data.password },
|
||
});
|
||
}
|
||
return (
|
||
<div className="w-full h-full sm:w-2/3 md:w-2/4 max-sm:p-8 pt-12">
|
||
<div className="space-y-3 md:space-y-4 h-full flex flex-col justify-start ">
|
||
<p className="text-sm md:text-base font-bold leading-tight tracking-tight text-blue dark:text-white">
|
||
لطفا جهت پیگیری درخواست و مشاهده وضعیت آن کد رهگیری و رمز عبور خود را
|
||
وارد نمایید.
|
||
</p>
|
||
|
||
<Form {...form}>
|
||
<form
|
||
onSubmit={form.handleSubmit(onSubmit)}
|
||
className="w-full flex flex-col mt-6 "
|
||
>
|
||
<div className="flex flex-row flex-wrap justify-between">
|
||
<FormField
|
||
control={form.control}
|
||
name="trackingNumber"
|
||
render={({ field }) => (
|
||
<FormItem className=" w-full lg:w-[48%]">
|
||
<FormLabel className="text-[#7C838A] text-sm font-medium">
|
||
کد پیگیری
|
||
</FormLabel>
|
||
<FormControl>
|
||
<Input
|
||
placeholder="کد پیگیری خود را وارد نمایید"
|
||
{...field}
|
||
/>
|
||
</FormControl>
|
||
<FormMessage />
|
||
</FormItem>
|
||
)}
|
||
/>
|
||
|
||
<FormField
|
||
control={form.control}
|
||
name="password"
|
||
render={({ field }) => (
|
||
<FormItem className=" w-full lg:w-[48%]">
|
||
<FormLabel className="text-[#7C838A] text-sm font-medium ">
|
||
رمز عبور
|
||
</FormLabel>
|
||
<FormControl>
|
||
<Input
|
||
placeholder="رمز عبور خود را وارد کنید"
|
||
{...field}
|
||
/>
|
||
</FormControl>
|
||
<FormMessage />
|
||
</FormItem>
|
||
)}
|
||
/>
|
||
</div>
|
||
|
||
<div className="flex justify-center sm:justify-end gap-2 w-full mt-8">
|
||
<Button
|
||
// href="/FollowResult"
|
||
type="submit"
|
||
className="bg-blue text-white min-w-max w-1/2 sm:w-1/3 lg:w-1/4 p-2 rounded-xl text-center"
|
||
>
|
||
پیگیری درخواست
|
||
</Button>
|
||
</div>
|
||
</form>
|
||
</Form>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|