-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add profile page * fix: svg properties * build: add react-easy-crop package * feat: add Avatar component * feat: crop uploaded image * linter * build: add styled components * linter * feat: add Button component * fix: Avatar size * linter * refactor: types * refactor: profile settings * feat: save cropped image * linter * fix: console errors * linter * feat: add delete confirmation modal * linter * feat: add user navigation * fix: types * linter * feat: add const instead of hardcoded value * feat: add styled components theme * feat: add missing 'use client' * feat: remove styled components * linter * chore: remove redundant file * linter * chore: add missing class * chore: use routes from constant * linter * refactor: move handlers to hooks * refactor: move mocked data out of component scope * refactor: use Typography * linter * refactor: use Typography * linter
- Loading branch information
1 parent
13e1d8f
commit 3ce6a33
Showing
48 changed files
with
772 additions
and
77 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
cd frontend | ||
|
||
yarn lint:fix && yarn format | ||
yarn compile |
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
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,35 @@ | ||
import { Breadcrumbs } from '@app/components/modules/Breadcrumbs'; | ||
import { ProfileSettings } from '@app/components/modules/ProfileSetting'; | ||
import { routes } from '@app/constants'; | ||
|
||
// TODO: get data from api | ||
const data = { | ||
firstName: 'Jane', | ||
lastName: 'Edge', | ||
email: 'example@gmail.com', | ||
ladders: [ | ||
{ | ||
ladderName: 'Front end', | ||
technology: 'React', | ||
band: 2, | ||
}, | ||
], | ||
notifications: { | ||
slack: false, | ||
email: false, | ||
}, | ||
}; | ||
|
||
export default async function LibraryPage() { | ||
return ( | ||
<div> | ||
<Breadcrumbs | ||
breadcrumbs={[ | ||
{ label: 'People', href: routes.people.index, current: false }, | ||
{ label: 'Profile setting', href: routes.people.myProfile, current: true }, | ||
]} | ||
/> | ||
<ProfileSettings data={data} /> | ||
</div> | ||
); | ||
} |
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,8 @@ | ||
export interface AvatarProps { | ||
variant?: AvatarVariant; | ||
firstName: string; | ||
lastName: string; | ||
imageUrl?: string | undefined; | ||
} | ||
|
||
export type AvatarVariant = '28' | '40' | '56' | '72' | '100' | '320'; |
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,34 @@ | ||
import Image from 'next/image'; | ||
import { AvatarProps, AvatarVariant } from './Avatar.interface'; | ||
import { generateClassNames } from '@app/utils'; | ||
|
||
const variants: { | ||
[key in AvatarVariant]: string; | ||
} = { | ||
'28': 'w-7 h-7 text-sm text-xs', | ||
'40': 'w-10 h-10 text-base', | ||
'56': 'w-14 h-14 text-xl', | ||
'72': 'w-[72px] h-[72px] text-2xl', | ||
'100': 'w-[100px] h-[100px] text-4xl', | ||
'320': 'w-80 h-80 text-5xl', | ||
}; | ||
|
||
export const Avatar: React.FC<AvatarProps> = ({ firstName, lastName, imageUrl, variant = '40' }) => { | ||
const avatarClass = generateClassNames( | ||
'rounded-full bg-blue-700 flex justify-center items-center', | ||
variants[variant], | ||
); | ||
|
||
return ( | ||
<div className={avatarClass}> | ||
{imageUrl ? ( | ||
<Image className="inline-block h-full w-full rounded-full" src={imageUrl} alt="User avatar" /> | ||
) : ( | ||
<span className="text-white"> | ||
{firstName[0]} | ||
{lastName[0]} | ||
</span> | ||
)} | ||
</div> | ||
); | ||
}; |
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 @@ | ||
export { Avatar } from './Avatar'; |
2 changes: 1 addition & 1 deletion
2
frontend/src/components/common/BucketCard/BucketCard.interface.ts
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,3 @@ | ||
export interface CardProps { | ||
title: string; | ||
} |
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,16 @@ | ||
import { CardProps } from './Card.interface'; | ||
import { PropsWithChildren } from 'react'; | ||
import { Typography } from '@app/components/common/Typography'; | ||
|
||
export const Card: React.FC<PropsWithChildren<CardProps>> = ({ title, children }) => { | ||
return ( | ||
<div className="rounded-xl bg-white shadow-sm ring-1 ring-navy-200/5 lg:w-[750px]"> | ||
<div className="px-4 py-6 sm:p-8"> | ||
<Typography as="h3" variant="head-s/semibold"> | ||
{title} | ||
</Typography> | ||
<div className="py-8">{children}</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
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 @@ | ||
export { Card } from './Card'; |
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
2 changes: 1 addition & 1 deletion
2
frontend/src/components/modules/AdvancementLevel/AdvancemetLevel.interface.ts
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
2 changes: 1 addition & 1 deletion
2
frontend/src/components/modules/BucketDetails/BucketDetails.interface.ts
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
2 changes: 1 addition & 1 deletion
2
frontend/src/components/modules/LadderDetails/LadderDetails.interface.ts
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
2 changes: 1 addition & 1 deletion
2
frontend/src/components/modules/LadderDetails/LadderDetails.tsx
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
2 changes: 1 addition & 1 deletion
2
frontend/src/components/modules/LibraryDetailed/LibraryDetailed.interface.ts
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
65 changes: 65 additions & 0 deletions
65
frontend/src/components/modules/ProfileSetting/ProfileSetting.hooks.ts
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,65 @@ | ||
import { ProfileSettingsHook } from '@app/components/modules/ProfileSetting/ProfileSetting.interface'; | ||
import { ChangeEvent, useState } from 'react'; | ||
import { getCroppedImg, readFile } from '@app/utils'; | ||
import { Area } from 'react-easy-crop'; | ||
|
||
export const useProfileSettings = (): ProfileSettingsHook => { | ||
const [imageSrc, setImageSrc] = useState<string | null>(null); | ||
const [cropModalOpen, setCropModalOpen] = useState(false); | ||
const [deleteModalOpen, setDeleteModalOpen] = useState(false); | ||
|
||
const handleFileChange = async (event: ChangeEvent<HTMLInputElement>) => { | ||
if (event.target.files && event.target.files.length > 0) { | ||
const file = event.target.files?.[0]; | ||
|
||
const imageDataUrl = await readFile(file); | ||
setImageSrc(imageDataUrl); | ||
setCropModalOpen(true); | ||
} | ||
}; | ||
|
||
const handleCloseCropModal = () => { | ||
setCropModalOpen(false); | ||
setImageSrc(null); | ||
}; | ||
|
||
const handleCloseDeleteModal = () => { | ||
setDeleteModalOpen(false); | ||
}; | ||
|
||
const handleOpenDeleteModal = () => setDeleteModalOpen(true); | ||
|
||
const handleSaveCroppedImage = async (croppedAreaPixels: Area | null) => { | ||
if (!croppedAreaPixels || !imageSrc) { | ||
// TODO | ||
return; | ||
} | ||
|
||
try { | ||
const img = await getCroppedImg(imageSrc, croppedAreaPixels); | ||
if (img) { | ||
// TODO: send new avatar to api | ||
setCropModalOpen(false); | ||
} | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
}; | ||
|
||
const handleDeleteImage = () => { | ||
// TODO: delete photo | ||
setDeleteModalOpen(false); | ||
}; | ||
|
||
return { | ||
imageSrc, | ||
handleFileChange, | ||
cropModalOpen, | ||
handleCloseCropModal, | ||
handleSaveCroppedImage, | ||
deleteModalOpen, | ||
handleCloseDeleteModal, | ||
handleDeleteImage, | ||
handleOpenDeleteModal, | ||
}; | ||
}; |
19 changes: 19 additions & 0 deletions
19
frontend/src/components/modules/ProfileSetting/ProfileSetting.interface.ts
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,19 @@ | ||
import { ChangeEvent } from 'react'; | ||
import { Area } from 'react-easy-crop'; | ||
import { User } from '@app/types/people'; | ||
|
||
export interface ProfileSettingsProps { | ||
data: User; | ||
} | ||
|
||
export interface ProfileSettingsHook { | ||
imageSrc: string | null; | ||
handleFileChange: (event: ChangeEvent<HTMLInputElement>) => Promise<void>; | ||
cropModalOpen: boolean; | ||
deleteModalOpen: boolean; | ||
handleCloseCropModal: () => void; | ||
handleCloseDeleteModal: () => void; | ||
handleDeleteImage: () => void; | ||
handleSaveCroppedImage: (croppedAreaPixels: Area | null) => void; | ||
handleOpenDeleteModal: () => void; | ||
} |
Oops, something went wrong.