Skip to content

Commit

Permalink
Redux removed: �✔ working fine
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanptm committed Aug 27, 2024
1 parent 8a4c673 commit de83fac
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 445 deletions.
14 changes: 2 additions & 12 deletions client/app/(patient)/signin/otp-verification/page.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
"use client";
import OtpVerificationSection from "@/components/forms/OtpForms";
import { useVerifyOtpMutation } from "@/lib/features/api/authApi";
import Image from "next/image";
import React, { FormEvent, useState } from "react";
import { useSelector } from "react-redux";
import {RootState} from '@/lib/store'

const OtpVerificationPage = () => {
const [otp,setOtp] = useState('')
const [verifyOtp, { isLoading , data}] = useVerifyOtpMutation();
const email = useSelector((state:RootState)=>state.auth.token) as string
const [otp, setOtp] = useState("");
const [isLoading, setLoading] = useState(false);

const handleVerify = async (e: FormEvent) => {
e.preventDefault();
try {
await verifyOtp({otp: parseInt(otp),email});
console.log(data);

} catch (error) {
console.log(error);

}
};

Expand All @@ -44,7 +35,6 @@ const OtpVerificationPage = () => {
isLoading={isLoading}
timer={30}
/>

</div>
</section>

Expand Down
13 changes: 0 additions & 13 deletions client/app/StoreProvider.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions client/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Plus_Jakarta_Sans } from "next/font/google";
import "../styles/globals.css";
import { cn } from "@/lib/utils";
import { ThemeProvider } from "@/components/ThemeProvider";
import { StoreProvider } from "./StoreProvider";
import NavBar from "@/components/NavBar";
import Footer from "@/components/Footer";
import { Toaster } from "@/components/ui/toaster";
Expand Down Expand Up @@ -31,14 +30,12 @@ export default function RootLayout({
return (
<html lang="en" suppressHydrationWarning>
<body className={cn("min-h-[600px] bg-dark-300 font-sans antialiased", inter.variable)}>
<StoreProvider>
<ThemeProvider attribute="class" defaultTheme="dark">
<NavBar />
<Toaster />
{children}
<Footer />
</ThemeProvider>
</StoreProvider>
</body>
</html>
);
Expand Down
10 changes: 2 additions & 8 deletions client/app/staff/@signin/otp-verification/page.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
'use client'
import OtpForm from "@/components/forms/OtpForms";
import { useVerifyOtpMutation } from "@/lib/features/api/authApi";
import { RootState } from "@/lib/store";
import Image from "next/image";
import Link from "next/link";
import { FormEvent, useState } from "react";
import { useSelector } from "react-redux";

const OtpVerificationPage = () => {
const [otp,setOtp] = useState('')
const [verifyOtp, { isLoading , data}] = useVerifyOtpMutation();
const email = useSelector((state:RootState)=>state.auth.token) as string

const [isLoading,setLoading] = useState(false)
const handleVerify = async (e: FormEvent) => {
e.preventDefault();
try {
await verifyOtp({otp: parseInt(otp),email});
console.log(data);


} catch (error) {
console.log(error);
Expand Down
1 change: 0 additions & 1 deletion client/app/staff/@signin/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"use server";
import SigninForm from "@/components/forms/admin/SigninForm";
import Image from "next/image";
import Link from "next/link";
Expand Down
73 changes: 32 additions & 41 deletions client/components/forms/OtpForms.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,39 @@
"use client";

import { FormEvent, useState} from "react";
import {
InputOTP,
InputOTPGroup,
InputOTPSlot,
} from "@/components/ui/input-otp";
import { FormEvent } from "react";
import { InputOTP, InputOTPGroup, InputOTPSlot } from "@/components/ui/input-otp";
import { Otptimer } from "otp-timer-ts";
import { OtpFromProps } from "@/types/fromTypes";
import SubmitButton from "../utils/SubmitButton";

export default function OtpVerificationSection({handleVerify,handleResend,timer,isLoading,otp,setOtp}:OtpFromProps) {

return (
<form className="space-y-6 flex-1" onSubmit={(e:FormEvent)=>handleVerify(e)}>
<section className="mb-12 space-y-4">
<h1 className="header">OTP Verification </h1>
<p className="text-dark-700">
Please enter the OTP sent to your registered mobile number.
</p>
</section>
<InputOTP
maxLength={6}
value={otp}
onChange={value => setOtp(value)}
className="mb-6"
>
<InputOTPGroup className="shad-otp">
<InputOTPSlot index={0} className="shad-otp-slot" />
<InputOTPSlot index={1} className="shad-otp-slot" />
<InputOTPSlot index={2} className="shad-otp-slot" />
<InputOTPSlot index={3} className="shad-otp-slot" />
<InputOTPSlot index={4} className="shad-otp-slot" />
<InputOTPSlot index={5} className="shad-otp-slot" />
</InputOTPGroup>
</InputOTP>
<div className="mt-4 mb-5 flex justify-between items-center">
<Otptimer seconds={timer} onResend={handleResend} />
</div>
<SubmitButton
isLoading={isLoading}
>
Verify OTP
</SubmitButton>
</form>
);
export default function OtpVerificationSection({
handleVerify,
handleResend,
timer,
isLoading,
otp,
setOtp,
}: OtpFromProps) {
return (
<form className="space-y-6 flex-1" onSubmit={(e: FormEvent) => handleVerify(e)}>
<section className="mb-12 space-y-4">
<h1 className="header">OTP Verification </h1>
<p className="text-dark-700">Please enter the OTP sent to your registered mobile number.</p>
</section>
<InputOTP maxLength={6} value={otp} onChange={(value) => setOtp(value)} className="mb-6">
<InputOTPGroup className="shad-otp">
<InputOTPSlot index={0} className="shad-otp-slot" />
<InputOTPSlot index={1} className="shad-otp-slot" />
<InputOTPSlot index={2} className="shad-otp-slot" />
<InputOTPSlot index={3} className="shad-otp-slot" />
<InputOTPSlot index={4} className="shad-otp-slot" />
<InputOTPSlot index={5} className="shad-otp-slot" />
</InputOTPGroup>
</InputOTP>
<div className="mt-4 mb-5 flex justify-between items-center">
<Otptimer seconds={timer} onResend={handleResend} />
</div>
<SubmitButton isLoading={isLoading}>Verify OTP</SubmitButton>
</form>
);
}
28 changes: 5 additions & 23 deletions client/components/forms/RegistrationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { SelectItem } from "../ui/select";

const RegistrationForm = () => {
const [isLoading, setIsLoading] = useState<boolean>(false);
// const [login] = useLoginMutation();
const form = useForm<z.infer<typeof registerFormValidation>>({
resolver: zodResolver(registerFormValidation),
defaultValues: {
Expand All @@ -38,17 +37,6 @@ const RegistrationForm = () => {
console.log(values);
setIsLoading(false);
}, 2000);
// try {
// const user = await login({
// phone: values.phone,
// password: values.password,
// }).unwrap();

// console.log("Login successful:", user);
// } catch (error) {
// console.error("Failed to log in:", error);
// } finally {
// }
};

return (
Expand All @@ -72,20 +60,16 @@ const RegistrationForm = () => {
control={form.control}
name="gender"
label="Gender *"
renderSkeleton={field => (
renderSkeleton={(field) => (
<FormControl>
<RadioGroup
className="flex h-11 gap-6 xl:justify-between"
onValueChange={field.onChange}
defaultValue={field.value}
>
defaultValue={field.value}>
{GenderOptions.map((option, i) => (
<div key={option} className="radio-group">
<RadioGroupItem value={option} id={option} />
<Label
htmlFor={option}
className="cursor-pointer"
>
<Label htmlFor={option} className="cursor-pointer">
{option}
</Label>
</div>
Expand All @@ -101,8 +85,7 @@ const RegistrationForm = () => {
control={form.control}
name="bloodType"
label="Your blood type *"
placeholder="Select blood type"
>
placeholder="Select blood type">
{BloodTypes.map((blood, i) => (
<SelectItem key={blood + i} value={blood}>
<div className="flex cursor-pointer items-center gap-2">
Expand All @@ -117,8 +100,7 @@ const RegistrationForm = () => {
control={form.control}
name="disease"
label="Primary Disease *"
placeholder="Select a disease"
>
placeholder="Select a disease">
{DiseaseOptions.map((disease, i) => (
<SelectItem key={disease + i} value={disease}>
<div className="flex cursor-pointer items-center gap-2">
Expand Down
16 changes: 3 additions & 13 deletions client/components/forms/SigninForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@ import SubmitButton from "@/components/utils/SubmitButton";
import { signinFormValidation } from "@/lib/validators/userValidation";
import Link from "next/link";
import { FormFieldType } from "@/types/fromTypes";
import { useSignInMutation } from "@/lib/features/api/authApi";
import { useToast } from "../ui/use-toast";
import { useRouter } from "next/navigation";
import { useDispatch } from "react-redux";
import { setCredentials } from "@/lib/features/slices/authSlice";

const LoginForm = () => {
const [signIn, { isLoading: isPosting, data, error: signinError }] = useSignInMutation();
const [error, setError] = useState("");
const { toast } = useToast();
const router = useRouter();
const dispatch = useDispatch();
const [isLoading,setLoading] = useState(false);

const form = useForm<z.infer<typeof signinFormValidation>>({
resolver: zodResolver(signinFormValidation),
Expand All @@ -33,20 +29,14 @@ const LoginForm = () => {

const onSubmit = async (values: z.infer<typeof signinFormValidation>) => {
try {
const result = await signIn(values).unwrap();
console.log(result);

dispatch(setCredentials({token:result.email}));
router.push("/signin/otp-verification");
toast({
title: "OTP Verification",
description: "Please check your email for the OTP.",
variant: "default",
});
router.push('/signin/otp-verification')
} catch (error: any) {
setError(error.data?.message || "An error occurred during sign-in.");
console.log(error);

toast({
title: "Sign-In Failed",
description: error.data?.message || "Please try again.",
Expand Down Expand Up @@ -87,7 +77,7 @@ const LoginForm = () => {

{error && <p className="text-red-500 text-sm mt-2">{error}</p>}

<SubmitButton isLoading={isPosting}>Sign In</SubmitButton>
<SubmitButton isLoading={isLoading}>Sign In</SubmitButton>
</form>
</Form>
);
Expand Down
7 changes: 2 additions & 5 deletions client/components/forms/SignupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Form } from "@/components/ui/form";
import CustomFormField from "@/components/utils/CustomFormField";
import SubmitButton from "@/components/utils/SubmitButton";
import { signupFormValidation } from "@/lib/validators/userValidation";
import { useSignUpMutation } from "@/lib/features/api/authApi";
import { FormFieldType } from "@/types/fromTypes";
import Link from "next/link";
import { useRouter } from "next/navigation";
Expand All @@ -19,6 +18,7 @@ const RegistrationForm = () => {
const [error, setError] = useState<string>("");
const router = useRouter();
const { toast } = useToast();
const [isLoading, setLoading] = useState(false);

const form = useForm<z.infer<typeof signupFormValidation>>({
resolver: zodResolver(signupFormValidation),
Expand All @@ -31,11 +31,8 @@ const RegistrationForm = () => {
},
});

const [signUp, { isLoading: isPosting, data: response, error: signUpError }] = useSignUpMutation();

const onSubmit = async (formData: z.infer<typeof signupFormValidation>) => {
try {
await signUp(formData).unwrap();
toast({
title: "Registration Successful",
description: "You have successfully registered. Please sign in.",
Expand Down Expand Up @@ -120,7 +117,7 @@ const RegistrationForm = () => {

{error && <p className="text-red-500 text-sm mt-2">{error}</p>}

<SubmitButton isLoading={isPosting}>Sign Up</SubmitButton>
<SubmitButton isLoading={isLoading}>Sign Up</SubmitButton>
</form>
</Form>
);
Expand Down
29 changes: 0 additions & 29 deletions client/components/utils/SearchInput.tsx

This file was deleted.

Loading

1 comment on commit de83fac

@vercel
Copy link

@vercel vercel bot commented on de83fac Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.