Skip to content

Commit d6c61eb

Browse files
Merge pull request #17 from akirachix/feature/authentication
Feature/authentication
2 parents 49cafb4 + fd8bb2b commit d6c61eb

File tree

13 files changed

+51
-15
lines changed

13 files changed

+51
-15
lines changed
-76.8 KB
Binary file not shown.
File renamed without changes.

fruitguard/src/app/Login/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function SignInForm() {
4646
return (
4747
<>
4848
<Image
49-
src="/images/Group239208.png"
49+
src="/images/fruitguard-logo.png"
5050
alt="FruitGuard Logo"
5151
width={100}
5252
height={100}

fruitguard/src/app/Register/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default function Register() {
7070
</div>
7171
<div className="w-1/2 flex items-center justify-center">
7272
<div className="w-full max-w-md p-6">
73-
<Image src="/images/Group239208.png" alt="FruitGuard Logo" width={100} height={100} className="mx-auto mb-10" priority/>
73+
<Image src="/images/fruitguard-logo.png" alt="FruitGuard Logo" width={100} height={100} className="mx-auto mb-10" priority/>
7474
<form onSubmit={handleSubmit} className="space-y-4">
7575
<div>
7676
<label htmlFor="first_name" className="block text-sm font-bold mb-1 text-xl">First Name</label>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import AdminLayout from "../sharedComponents/AdminLayout";
2+
import Profile from "../profile/page";
3+
4+
export default function AdminProfilePage(){
5+
return(
6+
<AdminLayout>
7+
<Profile/>
8+
</AdminLayout>
9+
)
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import AgrovetLayout from "../sharedComponents/AgrovetLayout";
2+
import Profile from "../profile/page";
3+
4+
5+
export default function AgrovetPage(){
6+
return(
7+
<AgrovetLayout>
8+
<Profile/>
9+
</AgrovetLayout>
10+
)
11+
}

fruitguard/src/app/profile/page.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ const mockedUpdateProfile = updateProfile as jest.Mock;
1515
describe('ProfilePage', () => {
1616
beforeEach(() => {
1717
jest.clearAllMocks();
18+
jest.spyOn(Storage.prototype, 'getItem').mockImplementation((key) => {
19+
if (key === 'token') {
20+
return 'test-token';
21+
}
22+
return null;
23+
});
1824
});
1925

2026
test('shows loading state when loading profile', () => {

fruitguard/src/app/profile/page.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ import { useEffect,useState } from "react";
44
import useProfile from "../hooks/useFetchProfile";
55
import { updateProfile } from "../utils/updateProfile";
66
import { HiOutlinePencilAlt } from "react-icons/hi";
7-
import AdminLayout from "../sharedComponents/AdminLayout";
87
import Button from "../sharedComponents/Button";
98
import Image from "next/image";
109

11-
const token = process.env.NEXT_PUBLIC_API_TOKEN || "";
1210

1311
export default function Profile() {
12+
const [token,setToken]=useState("")
13+
useEffect(()=>{
14+
const storedToken =localStorage.getItem("token");
15+
if (storedToken){
16+
setToken(storedToken);
17+
}
18+
},[]);
1419
const {profile, loading, error } = useProfile(token);
1520
const [formData, setFormData] = useState({first_name: "", last_name: "", email: "",});
1621
const [profileImage, setProfileImage] = useState<File |null>(null);
@@ -30,6 +35,10 @@ export default function Profile() {
3035
setFormData((oldData) => ({...oldData,[name]: value }));}
3136

3237
async function handleSubmit(event: React.FormEvent) {event.preventDefault();
38+
if (!token){
39+
setUpdateError("No authorization token found")
40+
return;
41+
}
3342
setUpdating(true);
3443
setUpdateError(null);
3544
setUpdateSuccess(false);
@@ -66,7 +75,7 @@ export default function Profile() {
6675
}}, [updateSuccess]);
6776

6877
return (
69-
<AdminLayout>
78+
7079
<div className="flex justify-end min-h-screen">
7180
<main className="w-4/5 px-35 flex flex-col justify-center items-center ml-30 font-nunito">
7281
<h1 className="text-[#7B4F36] text-2xl lg:text-3xl xl:text-3xl 2xl:text-4xl font-bold mb-15 -mt-4 text-left w-full">Profile</h1>
@@ -115,6 +124,6 @@ export default function Profile() {
115124
</div>)}
116125
</main>
117126
</div>
118-
</AdminLayout>
127+
119128
);
120129
}

fruitguard/src/app/roles/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default function Roles() {
1313
<div className="relative mb-12 mt-16 sm:mt-24 md:-mt-50">
1414
<div className="flex justify-center">
1515
<Image
16-
src="/Images/fruitguard.png"
16+
src="/images/fruitguard.png"
1717
alt="FruitGuard logo"
1818
width={150}
1919
height={80}

fruitguard/src/app/sharedComponents/Sidebar/AdminSidebar/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("AdminSidebar", () => {
3333
const teamLink = screen.getByRole("link", { name: /manage team/i });
3434
expect(teamLink).toHaveAttribute("aria-current", "page");
3535

36-
mockUsePathname.mockReturnValue("/profile");
36+
mockUsePathname.mockReturnValue("/admin-profile");
3737
rerender(<AdminSidebar />);
3838
const profileLink = screen.getByRole("link", { name: /profile/i });
3939
expect(profileLink).toHaveAttribute("aria-current", "page");

0 commit comments

Comments
 (0)