Skip to content

Commit

Permalink
Merge pull request #217 from ufsasewebmaster/Reset-password-page
Browse files Browse the repository at this point in the history
added reset password page
  • Loading branch information
T-Joseph-Kim authored Feb 26, 2025
2 parents e10240b + 33ed420 commit 12ef157
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/client/components/AuthForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const AuthForm = ({ additionalButton, buttonLabel, errorMessage, isSignUp = fals

<p className="text-md mt-4 text-center font-redhat">
{linkText}{" "}
<Link to={linkRoute} className="cursor-pointer text-saseBlue underline">
<Link to={isSignUp ? linkRoute : "/password"} className="cursor-pointer text-saseBlue underline">
{isSignUp ? "Login here." : "Click here to reset."}
</Link>
</p>
Expand Down
27 changes: 27 additions & 0 deletions src/client/routeTree.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Route as SetImport } from './routes/set'
import { Route as ResourcesImport } from './routes/resources'
import { Route as ProgramsImport } from './routes/programs'
import { Route as ProfileImport } from './routes/profile'
import { Route as PasswordImport } from './routes/password'
import { Route as LoginImport } from './routes/login'
import { Route as InternsImport } from './routes/interns'
import { Route as GalleryImport } from './routes/gallery'
Expand Down Expand Up @@ -86,6 +87,13 @@ const ProfileRoute = ProfileImport.update({
getParentRoute: () => rootRoute,
} as any)


const PasswordRoute = PasswordImport.update({
id: '/password',
path: '/password',
getParentRoute: () => rootRoute,
} as any)

const LoginRoute = LoginImport.update({
id: '/login',
path: '/login',
Expand Down Expand Up @@ -207,6 +215,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof LoginImport
parentRoute: typeof rootRoute
}
'/password': {
id: '/password'
path: '/password'
fullPath: '/password'
preLoaderRoute: typeof PasswordImport
parentRoute: typeof rootRoute
}
'/profile': {
id: '/profile'
path: '/profile'
Expand Down Expand Up @@ -285,6 +300,7 @@ export interface FileRoutesByFullPath {
'/gallery': typeof GalleryRoute
'/interns': typeof InternsRoute
'/login': typeof LoginRoute
'/password': typeof PasswordRoute
'/profile': typeof ProfileRoute
'/programs': typeof ProgramsRoute
'/resources': typeof ResourcesRoute
Expand All @@ -306,6 +322,7 @@ export interface FileRoutesByTo {
'/gallery': typeof GalleryRoute
'/interns': typeof InternsRoute
'/login': typeof LoginRoute
'/password': typeof PasswordRoute
'/profile': typeof ProfileRoute
'/programs': typeof ProgramsRoute
'/resources': typeof ResourcesRoute
Expand All @@ -328,6 +345,7 @@ export interface FileRoutesById {
'/gallery': typeof GalleryRoute
'/interns': typeof InternsRoute
'/login': typeof LoginRoute
'/password': typeof PasswordRoute
'/profile': typeof ProfileRoute
'/programs': typeof ProgramsRoute
'/resources': typeof ResourcesRoute
Expand All @@ -351,6 +369,7 @@ export interface FileRouteTypes {
| '/gallery'
| '/interns'
| '/login'
| '/password'
| '/profile'
| '/programs'
| '/resources'
Expand All @@ -371,6 +390,7 @@ export interface FileRouteTypes {
| '/gallery'
| '/interns'
| '/login'
| '/password'
| '/profile'
| '/programs'
| '/resources'
Expand All @@ -391,6 +411,7 @@ export interface FileRouteTypes {
| '/gallery'
| '/interns'
| '/login'
| '/password'
| '/profile'
| '/programs'
| '/resources'
Expand All @@ -413,6 +434,7 @@ export interface RootRouteChildren {
GalleryRoute: typeof GalleryRoute
InternsRoute: typeof InternsRoute
LoginRoute: typeof LoginRoute
PasswordRoute: typeof PasswordRoute
ProfileRoute: typeof ProfileRoute
ProgramsRoute: typeof ProgramsRoute
ResourcesRoute: typeof ResourcesRoute
Expand All @@ -434,6 +456,7 @@ const rootRouteChildren: RootRouteChildren = {
GalleryRoute: GalleryRoute,
InternsRoute: InternsRoute,
LoginRoute: LoginRoute,
PasswordRoute: PasswordRoute,
ProfileRoute: ProfileRoute,
ProgramsRoute: ProgramsRoute,
ResourcesRoute: ResourcesRoute,
Expand Down Expand Up @@ -464,6 +487,7 @@ export const routeTree = rootRoute
"/gallery",
"/interns",
"/login",
"/password",
"/profile",
"/programs",
"/resources",
Expand Down Expand Up @@ -502,6 +526,9 @@ export const routeTree = rootRoute
"/login": {
"filePath": "login.tsx"
},
"/password": {
"filePath": "password.tsx"
},
"/profile": {
"filePath": "profile.tsx"
},
Expand Down
91 changes: 91 additions & 0 deletions src/client/routes/password.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { cn } from "@/shared/utils";
import { Page } from "@components/Page";
import { createFileRoute, Link } from "@tanstack/react-router";
import { Button } from "@ui/button";
import { Input } from "@ui/input";
import React from "react";
import type { SubmitHandler } from "react-hook-form";
import { useForm } from "react-hook-form";
import ShadowCard from "../components/AuthShadowCard";
import { Logo } from "../components/navigation/Logo";

interface ForgotPasswordFormData {
email: string;
}

const StyledFormField = ({ children, hasError, icon }: { children: React.ReactNode; icon?: string; hasError?: boolean }) => (
<div className={cn("relative mb-1 w-full")}>
{icon && <span className={cn("pointer-events-none absolute left-3 top-[40%] z-10 h-5 w-5 -translate-y-1/2 text-gray-500", icon)} />}
{React.cloneElement(children as React.ReactElement, {
className: cn(
"mb-3 rounded-lg border border-gray-300 bg-saseGreenLight p-4 pl-10 placeholder-black opacity-90",
hasError ? "border-red-600" : "",
),
})}
</div>
);

const Password = () => {
const {
formState: { errors, isSubmitting },
handleSubmit,
register,
} = useForm<ForgotPasswordFormData>({ mode: "onBlur" });

const onSubmit: SubmitHandler<ForgotPasswordFormData> = async (data) => {
console.log("Reset request submitted for:", data.email);
// add reset password logic here!! //
};

return (
<Page>
<div className={cn("relative flex min-h-screen items-center justify-center")}>
<ShadowCard />
<form
onSubmit={handleSubmit(onSubmit)}
noValidate
className={cn(
"relative z-10 flex h-[32rem] w-full max-w-md flex-col items-center justify-start overflow-y-auto rounded-lg border bg-gray-100 p-6 shadow-xl",
)}
>
<div className={cn("mb-6 p-2")}>
<Logo />
</div>
<h3 className={cn("heading mb-3 pb-2 text-center font-oswald text-4xl font-semibold")}>Forgot Password</h3>
<p className={cn("mb-10 text-center text-gray-600")}>Please type the email associated with the account</p>
<StyledFormField icon="icon-[mdi--email-outline]" hasError={!!errors.email}>
<Input
id="email"
type="email"
placeholder="Email"
{...register("email", {
required: "Email is required",
pattern: {
value: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/,
message: "Enter a valid email address",
},
})}
/>
</StyledFormField>
{errors.email && <span className={cn("mb-4 font-redhat text-sm text-red-600")}>{errors.email.message}</span>}
<Button
type="submit"
className={cn("mt-5 w-full rounded-lg border bg-saseBlueLight p-5 font-semibold text-white")}
disabled={isSubmitting || !!errors.email}
>
Send Email Verification
</Button>
<p className={cn("text-md mt-6 text-center font-redhat")}>
<Link to="/login" className={cn("cursor-pointer text-saseBlue underline")}>
Back to Login
</Link>
</p>
</form>
</div>
</Page>
);
};

export const Route = createFileRoute("/password")({
component: Password,
});

0 comments on commit 12ef157

Please sign in to comment.