Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aait.web.g1.admas terefe.password change #438

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions aait/web/group-1/app/profile/account/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
'use client'

import React, { useState } from 'react';
import Image from 'next/image';
import { useChangePasswordMutation } from '@/store/features/user/userApi';


export default function Page() {
const [changePassword] = useChangePasswordMutation()
jebessaD marked this conversation as resolved.
Show resolved Hide resolved
const [oldPassword, setOldPassword] = useState('')
const [newPassword, setNewPassword] = useState('')
const [confirmPass, setConfirmPass] = useState('')

const handleSaveChanges = () => {
if(newPassword !== confirmPass) {
window.alert("Password don't match")
return
}
changePassword({"oldPassword": oldPassword, "newPassword": newPassword})

}


return (
<div className='flex flex-col space-y-16 font-montserrat'>
<div className='flex justify-between'>
<div>
<h3 className='text-[13px] text-[#5D5D5D] font-semibold'>Manage Your Account</h3>
<p className='text-[10px] text-[#868686] font-light'>You can change your password here</p>
</div>
<button
className='text-[10px] font-semibold bg-[#264FAD] rounded-md text-white px-12 py-2'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Utilize built-in colors instead of using hexadecimal codes.

onClick={handleSaveChanges}
>
Save Changes
</button>
</div>
<form className='grid grid-cols-3 place-items-start items-center text-[11px] font-poppins w-full max-w-md mx-auto gap-y-5'>
<label className='col-span-1 font-semibold text-[#565656]'>Current Password</label>
<div className='col-span-2 flex justify-between items-center py-3 px-5 rounded-lg bg-[#EFF3F9] w-full'>
<input
type="password"
className='focus:outline-none bg-[#EFF3F9]'
placeholder='Enter your current password'
onChange={(e) => setOldPassword(e.target.value)}
/>
<Image
src='/images/toggle-password-status.png'
width={ 12 }
height={ 12 }
alt=' toggle password visiblity'
className=''
/>
</div>
<label className='col-span-1 font-semibold text-[#565656]'>New Password</label>
<div className='col-span-2 flex justify-between items-center py-3 px-5 rounded-lg bg-[#EFF3F9] w-full'>
<input
type="password"
className='focus:outline-none bg-[#EFF3F9]'
placeholder='Enter new password'
onChange={(e) => setNewPassword(e.target.value)}
/>
<Image

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Icons, [react-icon package] instead of an image.

src='/images/toggle-password-status.png'
width={ 12 }
height={ 12 }
alt=' toggle password visiblity'
className=''
/>
</div>
<label className='col-span-1 font-semibold text-[#565656]'>Confirm Password</label>
<div className='col-span-2 flex justify-between items-center py-3 px-5 rounded-lg bg-[#EFF3F9] w-full'>
<input
type="password"
className='focus:outline-none bg-[#EFF3F9]'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Utilize built-in colors instead of using hexadecimal codes.

placeholder='Confirm new password'
onChange={(e) => setConfirmPass(e.target.value)}
/>
<Image

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Icons, [react-icon package] instead of an image.

src='/images/toggle-password-status.png'
width={ 12 }
height={ 12 }
alt=' toggle password visiblity'
className=''
/>
</div>
</form>
</div>
);
}


47 changes: 47 additions & 0 deletions aait/web/group-1/app/profile/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use client';

import React from 'react';
import { usePathname } from 'next/navigation';
import Link from 'next/link';

export default function ProfileLayout({
children,
}: {
children: React.ReactNode
}) {
const links: string[] = [ 'Personal Information', 'My Blogs', 'Account Setting' ];
const linkPathname = new Map<string, string>([
['Personal Information', '/profile'],
['My Blogs', '/profile/my-blogs'],
['Account Setting', '/profile/account']
]);
const pathname = usePathname();

return (
<div className='px-[100px] flex flex-col space-y-5 font-montserrat'>
<h1 className='text-[22px] font-semibold'>Profile</h1>
<div className={ `flex justify-between items-center text-md border-b ${ pathname === '/profile/my-blogs' ? 'pb-2' : 'pb-4' }` }>
<div className='flex space-x-10 text-[12px] text-[#494949] font-semibold'>
{
links.map(link => (
<Link
href={ linkPathname.get(link) as string }
className={
pathname === linkPathname.get(link) ? 'border-b-2 border-[#264FAD] -mb-4' : ''
}
>{ link }</Link>
))
}
</div>
{ pathname === linkPathname.get('My Blogs') && <button className='text-[10px] font-semibold bg-[#264FAD] rounded-md text-white px-12 py-2'>New Blog</button> }
</div>
{ children }
</div>
);
}






20 changes: 20 additions & 0 deletions aait/web/group-1/app/profile/my-blogs/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import Card from '@/components/profile/Card';

export default function Page() {
return (
<div className='flex flex-col space-y-5 font-montserrat'>
<div>
<h3 className='text-[13px] text-[#5D5D5D] font-semibold'>Manage Blogs</h3>
<p className='text-[10px] text-[#868686] font-light'>Edit, Delete and View the status of your blogs</p>
</div>
<div className='grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 place-items-center gap-4'>
{Array.from({ length: 8 }).map((_, index) => (
<div key={index} className=''>
<Card />
</div>
))}
</div>
</div>
);
}
118 changes: 118 additions & 0 deletions aait/web/group-1/app/profile/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
'use client'
import React, { useRef, useState } from 'react';
import Image from 'next/image';
import { useEditProfileMutation } from '@/store/features/user/userApi';

const userData = localStorage.getItem('user');
const currUser = userData ? JSON.parse(userData) : null;

export default function Page() {
const trimmedName = currUser?.userName.trim()
const [fName, lName] = trimmedName.split(/\s+/)
const fileInputRef = useRef(null)
const [firstName, setFirstName] = useState(fName || '')
const [lastName, setLastName] = useState(lName || '')
const [email, setEmail] = useState(currUser?.userEmail || '')
const [photo, setPhoto] = useState<File | null>(null)
const [editProfile, {isError, isLoading, isSuccess}] = useEditProfileMutation()

const handleDivClick = () => {
if (fileInputRef.current) {
fileInputRef.current.click();
}
};

const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
if(event.target.files) {
const file = event.target.files[0];
setPhoto(file)
}
}

const handleSaveChanges = async (event: React.FormEvent) => {
event.preventDefault()
const newUserData = new FormData()
newUserData.append("name", `${firstName} ${lastName}`)
newUserData.append("email", email)
if(photo) {
newUserData.append("image", photo)
}

editProfile(newUserData)


}

return (
<div className='flex flex-col space-y-5 font-montserrat'>
<div className='flex justify-between'>
<div>
<h3 className='text-[13px] text-[#5D5D5D] font-semibold'>Manage Personal Information</h3>
<p className='text-[10px] text-[#868686] font-light'>Add all the required information about yourself</p>
</div>
<button
className='text-[10px] font-semibold bg-[#264FAD] active:bg-blue-500 rounded-md text-white px-12 py-2'
onClick={handleSaveChanges}
>
Save Changes
</button>
</div>
<div className='grid grid-cols-3 lg:pr-[300px] gap-10 text-[10px] md:text-[11px]'>
<h4 className=' text-[#565656] font-semibold font-poppins col-span-1'>Name <span className='text-[#F64040]'>*</span></h4>
<input
type="text"
className=" text-[#565656] font-semibold font-poppins col-span-1 border border-gray-300 rounded-lg py-2 px-3"
value={firstName}
onChange={(e) => setFirstName(e.target.value)}
/>
<input
type="text"
className=" text-[#565656] font-semibold font-poppins col-span-1 border border-gray-300 rounded-lg py-2 px-3"
value={lastName}
onChange={(e) => setLastName(e.target.value)}
/>
<h4 className=' text-[#565656] font-semibold font-poppins col-span-1'>Email <span className='text-[#F64040]'>*</span></h4>
<input
type="email"
className=" text-[#565656] font-semibold font-poppins col-span-2 border border-gray-300 rounded-lg py-2 px-3"
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
<h4 className=' text-[#565656] font-semibold font-poppins col-span-1'>Your Photo <span className='text-[#F64040]'>*</span></h4>
<div className='col-span-2 flex items-start justify-center md:justify-start space-x-0 md:space-x-16'>
<Image
className='hidden md:block'
src={photo ? URL.createObjectURL(photo) : currUser?.userProfile}
width={ 50 }
height={ 50 }
alt='small profile image'
/>
<div
className='text-center border flex flex-col justify-center items-center border-gray-300 rounded-lg h-full px-10 py-12'
onClick={handleDivClick}
>
<Image
src='/images/file-upload-image.png'
width={ 25 }
height={ 25 }
alt='file upload image'
/>
<p className='text-[10px] font-semibold sm:text-[11px] text-[#858585]'>
{' '}
<span className='text-[#565656]'>Clik to upload</span> or drag and drop
SVG, PNG, JPG or GIF(max 800x400px)
</p>
<input
type='file'
ref={fileInputRef}
style={{ display: 'none' }}
onChange={handleFileChange}
/>
</div>
</div>
</div>
</div>
);
}


36 changes: 36 additions & 0 deletions aait/web/group-1/store/features/user/userApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';

const BASE_URL = 'https://a2sv-backend.onrender.com/api';

export const profileApi = createApi({
reducerPath: 'profileApi',
baseQuery: fetchBaseQuery({
baseUrl: BASE_URL,
prepareHeaders: (headers, { getState }) => {
const userData = localStorage.getItem('user');
const token = userData ? JSON.parse(userData)?.token : null;
if(token) {
headers.set('Authorization', `Bearer ${token}`);
}
return headers;
}
}),
endpoints: (builder) => ({
editProfile: builder.mutation({
query: (newUserData) => ({
url: '/auth/edit-profile',
method: 'PATCH',
body: newUserData,
}),
}),
changePassword: builder.mutation({
query: (newPasswordInfo) => ({
url: '/auth/change-password',
method: 'PATCH',
body: newPasswordInfo,
}),
}),
}),
});

export const { useEditProfileMutation, useChangePasswordMutation } = profileApi;
7 changes: 4 additions & 3 deletions aait/web/group-1/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { configureStore, getDefaultMiddleware } from '@reduxjs/toolkit'
import { authApi } from './auth/authApi'
import { profileApi } from './features/user/userApi'
import { teamMembersApi } from "./features/team-members/team-members";
import { blogApi } from './blog/blogApi';


export const store = configureStore({
reducer: {
[authApi.reducerPath]: authApi.reducer,
[blogApi.reducerPath]: blogApi.reducer,
[profileApi.reducerPath]: profileApi.reducer,
[teamMembersApi.reducerPath]: teamMembersApi.reducer,
},

middleware: getDefaultMiddleware => getDefaultMiddleware().concat(authApi.middleware, blogApi.middleware, teamMembersApi.middleware)
middleware: getDefaultMiddleware => getDefaultMiddleware()
.concat(authApi.middleware, blogApi.middleware, profileApi.middleware, teamMembersApi.middleware)
})

export type RootState = ReturnType<typeof store.getState>
Expand Down