-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: major updates using drawer and moving styles around
- Loading branch information
1 parent
000325f
commit ed2dd4c
Showing
13 changed files
with
269 additions
and
235 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,3 @@ | ||
import { Link } from "react-router-dom"; | ||
|
||
export function Footer() { | ||
return ( | ||
<footer className="absolute bottom-0 left-0 flex w-full justify-center"> | ||
<section className="container flex items-center justify-between p-6 sm:p-4"> | ||
<Link to="/"> | ||
<img src="/images/mtc-logo.svg" width={58} height={54} alt="Planet Earth" className="" /> | ||
</Link> | ||
|
||
<nav className="flex flex-grow justify-center"> | ||
<Link to="/about" className="text-sky-400 underline"> | ||
About | ||
</Link> | ||
</nav> | ||
|
||
<span></span> | ||
</section> | ||
</footer> | ||
); | ||
return <footer className="absolute bottom-0 left-0 flex w-full justify-center"></footer>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { useMutation } from "@apollo/client"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { Button, Input, Typography } from "@material-tailwind/react"; | ||
import { SubmitHandler, useForm } from "react-hook-form"; | ||
import { Link } from "react-router-dom"; | ||
import { toast } from "react-toastify"; | ||
import { z } from "zod"; | ||
import { gql } from "@generated/index.ts"; | ||
|
||
const LOGIN_USER = gql(/* GraphQL */ ` | ||
mutation LoginUser($input: LoginInput!) { | ||
loginUser(input: $input) { | ||
access_token | ||
} | ||
} | ||
`); | ||
|
||
const formSchema = z.object({ | ||
email: z.string().email(), | ||
password: z.string().min(1), | ||
}); | ||
|
||
export function LoginForm({ handleLoginSuccess }: { handleLoginSuccess: () => Promise<void> }) { | ||
const { | ||
register, | ||
handleSubmit, | ||
reset, | ||
formState: { errors }, | ||
} = useForm<z.infer<typeof formSchema>>({ | ||
resolver: zodResolver(formSchema), | ||
defaultValues: { | ||
email: "", | ||
password: "", | ||
}, | ||
}); | ||
|
||
const [loginMutation, { loading: isLoadingLogin, error: mutationError }] = useMutation(LOGIN_USER, { | ||
onCompleted: async data => { | ||
data.loginUser.access_token && (await handleLoginSuccess()); | ||
toast.success("Logged in successfully!"); | ||
reset(); | ||
}, | ||
}); | ||
|
||
const onSubmit: SubmitHandler<z.infer<typeof formSchema>> = async (values, event) => { | ||
event?.preventDefault(); | ||
|
||
try { | ||
await loginMutation({ | ||
variables: { | ||
input: { | ||
email: values.email, | ||
password: values.password, | ||
}, | ||
}, | ||
}); | ||
} catch (e) { | ||
console.log("Something went wrong", e); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="w-full p-4"> | ||
<div className="flex w-96 items-center justify-between rounded-t border-b pb-2"> | ||
<Typography variant="h4" color="blue-gray"> | ||
Sign in | ||
</Typography> | ||
</div> | ||
|
||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-3 py-4"> | ||
<Input | ||
{...register("email")} | ||
name="email" | ||
size="lg" | ||
label="Email address" | ||
placeholder="[email protected]" | ||
error={!!errors.email} | ||
/> | ||
|
||
<Input | ||
{...register("password")} | ||
name="password" | ||
size="lg" | ||
type="password" | ||
label="Password" | ||
placeholder="*******" | ||
error={!!errors.password} | ||
/> | ||
|
||
{mutationError?.message && <p className="text-sm text-red-500">{mutationError.message}</p>} | ||
|
||
<Button type="submit" disabled={isLoadingLogin} loading={isLoadingLogin}> | ||
Login to your account | ||
</Button> | ||
|
||
<div className="text-sm font-medium text-gray-500"> | ||
Not registered? | ||
<Link to="/register" className="text-blue-700 hover:underline"> | ||
Create an account | ||
</Link> | ||
</div> | ||
</form> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.