Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
OGreeni committed Apr 15, 2024
1 parent e0352e3 commit bcb8510
Show file tree
Hide file tree
Showing 21 changed files with 228 additions and 262 deletions.
12 changes: 10 additions & 2 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
NEXT_PUBLIC_API_BASE_URL=https://combined-community-action.vercel.app
#NEXT_PUBLIC_API_BASE_URL=http://localhost:8000
127 changes: 127 additions & 0 deletions frontend/src/app/auth/admin/forgot-password/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
'use client';
import { FC, FormEventHandler, useEffect, useState } from 'react';
import Image from 'next/image';
import { TextInput } from '@/components/core/TextInput';
import { Button } from '@/components/core/Button';
import Link from 'next/link';
import { useRouter, useSearchParams } from 'next/navigation';
import { useUserContext } from '@/context/userContext';
import { CodeInput } from '@/components/auth/CodeInput';
import { cookies } from 'next/headers';

interface PageProps {}

const Page: FC<PageProps> = () => {
const [emailInput, setEmailInput] = useState('');
const [passwordInput, setPasswordInput] = useState('');
const [confirmPasswordInput, setConfirmPasswordInput] = useState('');
const router = useRouter();
const searchParams = useSearchParams();

const jwt = searchParams.get('jwt');

const handleSubmit: FormEventHandler<HTMLFormElement> = (e) => {
e.preventDefault();

if (!jwt) {
fetch(
`${process.env.NEXT_PUBLIC_API_BASE_URL}/auth/admin/forgot-password`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: emailInput,
}),
credentials: 'include',
}
).catch((err) => console.error(err));
} else {
fetch(
`${process.env.NEXT_PUBLIC_API_BASE_URL}/auth/admin/verify-forgot-password`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
token: jwt,
password: passwordInput,
}),
credentials: 'include',
}
)
.then((res) => {
if (res.ok) {
router.push('/auth/login');
}
})
.catch((err) => console.error(err));
}
};

if (jwt) {
return (
<main>
<form
className="mt-52 flex flex-col items-center gap-6"
onSubmit={handleSubmit}
>
<Image
src="/images/logo.png"
alt="logo"
width={239}
height={239}
/>
<span className="text-3xl font-bold text-tertiary">
Forgot Password
</span>
<TextInput
value={passwordInput}
onChange={setPasswordInput}
placeholder={'New password'}
required
type="password"
/>
<TextInput
value={confirmPasswordInput}
onChange={setConfirmPasswordInput}
placeholder={'Confirm password'}
required
type="password"
/>
<Button type="submit" text={'Change Password'} />
</form>
</main>
);
}

return (
<main>
<form
className="mt-52 flex flex-col items-center gap-6"
onSubmit={handleSubmit}
>
<Image
src="/images/logo.png"
alt="logo"
width={239}
height={239}
/>
<span className="text-3xl font-bold text-tertiary">
Forgot Password
</span>
<TextInput
value={emailInput}
onChange={setEmailInput}
placeholder={'Email'}
required
/>
<Button type="submit" text={'Send Email'} />
</form>
</main>
);
};

export default Page;
12 changes: 2 additions & 10 deletions frontend/src/app/auth/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Link from 'next/link';
import { useRouter } from 'next/navigation';
import { useUserContext } from '@/context/userContext';
import { CodeInput } from '@/components/auth/CodeInput';
import { cookies } from 'next/headers';

interface PageProps {}

Expand Down Expand Up @@ -142,18 +141,11 @@ const Page: FC<PageProps> = () => {
{loginType === 'ADMIN' && (
<Link
className="text-sm text-[#017BAF] hover:underline"
href="/"
href="/auth/admin/forgot-password"
>
Forgot Username or Password?
Forgot Password?
</Link>
)}
<button
type="button"
className="text-sm text-[#017BAF] hover:underline"
onClick={() => router.push('register')}
>
Don&apos;t have an account? Register
</button>
</div>
<Button
type="submit"
Expand Down
163 changes: 0 additions & 163 deletions frontend/src/app/auth/register/page.tsx

This file was deleted.

Loading

0 comments on commit bcb8510

Please sign in to comment.