Skip to content

Commit

Permalink
add final fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
OGreeni committed Apr 15, 2024
1 parent e9ea614 commit d75824f
Show file tree
Hide file tree
Showing 21 changed files with 327 additions and 253 deletions.
25 changes: 24 additions & 1 deletion .idea/workspace.xml

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

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;
11 changes: 2 additions & 9 deletions frontend/src/app/auth/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,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.

21 changes: 12 additions & 9 deletions frontend/src/app/client-dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client';
import { useEffect, useState } from 'react';
import { API_BASE_URL } from '../globals';
import Loading from '@/components/core/Loading';
import { ClientDetailsPopup } from '@/components/client-dashboard/ClientDetailsPopup/ClientDetailsPopup';
import { Client } from '@/types/backend';
Expand Down Expand Up @@ -116,13 +115,17 @@ export default function Dashboard() {

const onPopupClose = () => setSelectedClient(null);
const onPopupSubmit = (updatedClient: Client) => {
fetch(API_BASE_URL + `/client/${updatedClient.id}`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(updatedClient),
})
fetch(
process.env.NEXT_PUBLIC_API_BASE_URL +
`/client/${updatedClient.id}`,
{
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(updatedClient),
}
)
.then((response) => response.json())
.then((respdata) => {
if (respdata.error) {
Expand Down Expand Up @@ -266,7 +269,7 @@ export default function Dashboard() {
latestOrder?.deliverBy
).toLocaleString()}`}
>
{toTitleCase(latestOrder?.status)}
{toTitleCase(latestOrder?.status ?? '')}
</td>
<td
className={`rounded-md bg-[#F5F5F5] px-3 py-1 text-center text-[16px] font-bold text-white hover:cursor-pointer ${
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit d75824f

Please sign in to comment.