-
Notifications
You must be signed in to change notification settings - Fork 279
feat: list user experiences #5015
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
166fb60
feat: list user experiences
sshanzel 73ee273
Merge branch 'MI-1027-profile' into MI-1027-experiences
sshanzel a0b54e5
feat: support type with links
sshanzel 8730e50
tmp: dummy data
sshanzel 65a255e
refactor: user experience type safe
sshanzel 89097fc
fix: format date issue
rebelchris fde928a
Merge branch 'MI-1027-profile' of github.com:dailydotdev/apps into MI…
rebelchris 1e3d992
fix: remove need for dividers
rebelchris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
packages/shared/src/features/profile/components/experience/ProfileUserExperiences.tsx
This file contains hidden or 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,46 @@ | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import type { ReactElement } from 'react'; | ||
| import React, { useMemo } from 'react'; | ||
| import { generateQueryKey, RequestKey, StaleTime } from '../../../../lib/query'; | ||
| import { useAuthContext } from '../../../../contexts/AuthContext'; | ||
| import type { PublicProfile } from '../../../../lib/user'; | ||
| import { getUserProfileExperiences } from '../../../../graphql/user/profile'; | ||
| import { UserExperienceList } from './UserExperiencesList'; | ||
|
|
||
| interface ProfileUserExperiencesProps { | ||
| user: PublicProfile; | ||
| } | ||
|
|
||
| export function ProfileUserExperiences({ | ||
| user, | ||
| }: ProfileUserExperiencesProps): ReactElement { | ||
| const { user: loggedUser } = useAuthContext(); | ||
| const { data } = useQuery({ | ||
| queryKey: generateQueryKey( | ||
| RequestKey.UserExperience, | ||
| loggedUser, | ||
| 'profile', | ||
| ), | ||
| queryFn: () => getUserProfileExperiences(user.id), | ||
| staleTime: StaleTime.Default, | ||
| }); | ||
|
|
||
| const list = useMemo( | ||
| () => ({ | ||
| work: data?.work?.edges?.map(({ node }) => node), | ||
| education: data?.education?.edges?.map(({ node }) => node), | ||
| cert: data?.certification?.edges?.map(({ node }) => node), | ||
| project: data?.project?.edges?.map(({ node }) => node), | ||
| }), | ||
| [data], | ||
| ); | ||
|
|
||
| return ( | ||
| <> | ||
| <UserExperienceList experiences={list.work} title="Work Experiences" /> | ||
| <UserExperienceList experiences={list.education} title="Education" /> | ||
| <UserExperienceList experiences={list.cert} title="Certifications" /> | ||
| <UserExperienceList experiences={list.project} title="Projects" /> | ||
| </> | ||
| ); | ||
| } |
142 changes: 142 additions & 0 deletions
142
packages/shared/src/features/profile/components/experience/UserExperienceItem.tsx
This file contains hidden or 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,142 @@ | ||
| import type { ReactElement } from 'react'; | ||
| import React from 'react'; | ||
| import classNames from 'classnames'; | ||
| import type { | ||
| UserExperience, | ||
| UserExperienceCertification, | ||
| UserExperienceProject, | ||
| UserExperienceWork, | ||
| } from '../../../../graphql/user/profile'; | ||
| import { Image, ImageType } from '../../../../components/image/Image'; | ||
| import { Pill, PillSize } from '../../../../components/Pill'; | ||
| import { | ||
| Typography, | ||
| TypographyType, | ||
| TypographyColor, | ||
| } from '../../../../components/typography/Typography'; | ||
| import { formatDate, TimeFormatType } from '../../../../lib/dateFormat'; | ||
| import { anchorDefaultRel, concatStrings } from '../../../../lib/strings'; | ||
| import { currrentPill } from './common'; | ||
| import { Button } from '../../../../components/buttons/Button'; | ||
|
|
||
| interface UserExperienceItemProps { | ||
| experience: UserExperience; | ||
| grouped?: { | ||
| isLastItem?: boolean; | ||
| }; | ||
| } | ||
|
|
||
| export function UserExperienceItem({ | ||
| experience, | ||
| grouped, | ||
| }: UserExperienceItemProps): ReactElement { | ||
| const { company, title, description, startedAt, endedAt, subtitle } = | ||
| experience; | ||
| const { skills, verified } = experience as UserExperienceWork; | ||
| const { url } = experience as UserExperienceProject; | ||
| const { externalReferenceId } = experience as UserExperienceCertification; | ||
|
|
||
| return ( | ||
| <li key={experience.id} className="flex flex-row gap-2"> | ||
| {grouped ? ( | ||
| <div className="relative flex w-8 justify-center overflow-hidden"> | ||
| <div className="absolute left-4 h-6 w-8 -translate-x-px rounded-bl-10 border-b-2 border-l-2 border-accent-pepper-subtle" /> | ||
| {!grouped.isLastItem && ( | ||
| <div className="absolute h-full w-0.5 bg-accent-pepper-subtle" /> | ||
| )} | ||
| </div> | ||
| ) : ( | ||
| <Image | ||
| className="h-8 w-8 rounded-max object-cover" | ||
| type={ImageType.Organization} | ||
| src={company?.image} | ||
| /> | ||
| )} | ||
| <div | ||
| className={classNames('flex flex-1 flex-col gap-2', { | ||
| 'pt-3': !!grouped, | ||
| })} | ||
| > | ||
| <div className="flex flex-col gap-1"> | ||
| <Typography type={TypographyType.Subhead} bold> | ||
| {title} | ||
| {!grouped && !endedAt && currrentPill} | ||
| {url && ( | ||
| <Button | ||
| tag="a" | ||
| target="_blank" | ||
| rel={anchorDefaultRel} | ||
| href={url} | ||
| /> | ||
| )} | ||
| </Typography> | ||
| {!!subtitle && ( | ||
| <Typography | ||
| type={TypographyType.Footnote} | ||
| color={TypographyColor.Secondary} | ||
| > | ||
| {subtitle} | ||
| </Typography> | ||
| )} | ||
| {!grouped && ( | ||
| <Typography | ||
| type={TypographyType.Footnote} | ||
| color={TypographyColor.Secondary} | ||
| > | ||
| {company?.name} | ||
| {!!verified && ( | ||
| <span className="ml-1 text-text-quaternary">Verified</span> | ||
| )} | ||
| </Typography> | ||
| )} | ||
| <Typography | ||
| type={TypographyType.Footnote} | ||
| color={TypographyColor.Tertiary} | ||
| > | ||
| {concatStrings( | ||
| [ | ||
| formatDate({ | ||
| value: startedAt, | ||
| type: TimeFormatType.TopReaderBadge, | ||
| }), | ||
| !!endedAt && | ||
| formatDate({ | ||
| value: endedAt, | ||
| type: TimeFormatType.TopReaderBadge, | ||
| }), | ||
| ], | ||
| ' - ', | ||
| )} | ||
| </Typography> | ||
| {!!externalReferenceId && ( | ||
| <Typography | ||
| type={TypographyType.Footnote} | ||
| color={TypographyColor.Tertiary} | ||
| > | ||
| {externalReferenceId} | ||
| </Typography> | ||
| )} | ||
| </div> | ||
| <Typography | ||
| type={TypographyType.Subhead} | ||
| color={TypographyColor.Secondary} | ||
| className="flex w-full max-w-full flex-1 break-words" | ||
| > | ||
| {description} | ||
| </Typography> | ||
| {skills?.length > 0 && ( | ||
| <div className="flex flex-row gap-2"> | ||
| {skills.map((skill) => ( | ||
| <Pill | ||
| key={skill.value} | ||
| label={skill.value} | ||
| size={PillSize.Small} | ||
| className="border border-border-subtlest-tertiary text-text-quaternary" | ||
| /> | ||
| ))} | ||
| </div> | ||
| )} | ||
| </div> | ||
| </li> | ||
| ); | ||
| } |
63 changes: 63 additions & 0 deletions
63
packages/shared/src/features/profile/components/experience/UserExperiencesGroupedList.tsx
This file contains hidden or 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,63 @@ | ||
| import type { ReactElement } from 'react'; | ||
| import React from 'react'; | ||
| import type { UserExperience } from '../../../../graphql/user/profile'; | ||
| import { Image, ImageType } from '../../../../components/image/Image'; | ||
| import { | ||
| Typography, | ||
| TypographyType, | ||
| TypographyColor, | ||
| } from '../../../../components/typography/Typography'; | ||
| import { UserExperienceItem } from './UserExperienceItem'; | ||
| import { formatDate, TimeFormatType } from '../../../../lib/dateFormat'; | ||
| import { currrentPill } from './common'; | ||
|
|
||
| interface UserExperiencesGroupedListProps { | ||
| company: string; | ||
| experiences: UserExperience[]; | ||
| } | ||
|
|
||
| export function UserExperiencesGroupedList({ | ||
| company, | ||
| experiences, | ||
| }: UserExperiencesGroupedListProps): ReactElement { | ||
| const [first] = experiences; | ||
| const last = experiences[experiences.length - 1]; | ||
| const duration = formatDate({ | ||
| value: new Date(last.startedAt), | ||
| type: TimeFormatType.Experience, | ||
| now: first.endedAt ? new Date(first.endedAt) : new Date(), | ||
| }); | ||
|
|
||
| return ( | ||
| <> | ||
| <li className="flex flex-row gap-2"> | ||
| <Image | ||
| className="h-8 w-8 rounded-max object-cover" | ||
| type={ImageType.Organization} | ||
| src={first.company?.image} | ||
| /> | ||
| <div className="flex flex-1 flex-col"> | ||
| <Typography type={TypographyType.Subhead} bold> | ||
| {company} | ||
| {!first.endedAt && currrentPill} | ||
| </Typography> | ||
| <Typography | ||
| type={TypographyType.Footnote} | ||
| color={TypographyColor.Secondary} | ||
| > | ||
| {duration} | ||
| </Typography> | ||
| </div> | ||
| </li> | ||
| <ul className="flex flex-col"> | ||
| {experiences.map((experience, index) => ( | ||
| <UserExperienceItem | ||
| key={experience.id} | ||
| experience={experience} | ||
| grouped={{ isLastItem: index === experiences.length - 1 }} | ||
| /> | ||
| ))} | ||
| </ul> | ||
| </> | ||
| ); | ||
| } |
69 changes: 69 additions & 0 deletions
69
packages/shared/src/features/profile/components/experience/UserExperiencesList.tsx
This file contains hidden or 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,69 @@ | ||
| import type { ReactElement } from 'react'; | ||
| import React, { useMemo } from 'react'; | ||
| import type { UserExperience } from '../../../../graphql/user/profile'; | ||
| import { | ||
| Typography, | ||
| TypographyTag, | ||
| TypographyType, | ||
| } from '../../../../components/typography/Typography'; | ||
| import { UserExperienceItem } from './UserExperienceItem'; | ||
| import { UserExperiencesGroupedList } from './UserExperiencesGroupedList'; | ||
|
|
||
| interface UserExperienceListProps<T extends UserExperience> { | ||
| experiences: T[]; | ||
| title: string; | ||
| } | ||
|
|
||
| const groupListByCompany = <T extends UserExperience>( | ||
| experiences: T[], | ||
| ): [string, T[]][] => { | ||
| if (!experiences?.length) { | ||
| return []; | ||
| } | ||
|
|
||
| const grouped = experiences.reduce((acc, node) => { | ||
| const name = node.customCompanyName || node.company?.name; | ||
| if (!acc[name]) { | ||
| acc[name] = []; | ||
| } | ||
| acc[name].push(node); | ||
| return acc; | ||
| }, {} as Record<string, T[]>); | ||
|
|
||
| return Object.entries(grouped); | ||
| }; | ||
|
|
||
| export function UserExperienceList<T extends UserExperience>({ | ||
| experiences, | ||
| title, | ||
| }: UserExperienceListProps<T>): ReactElement { | ||
| const groupedByCompany: [string, T[]][] = useMemo( | ||
| () => groupListByCompany(experiences), | ||
| [experiences], | ||
| ); | ||
|
|
||
| if (!experiences?.length) { | ||
| return <></>; | ||
| } | ||
|
|
||
| return ( | ||
| <div className="flex flex-col gap-3 pt-4"> | ||
| <Typography tag={TypographyTag.H2} type={TypographyType.Body} bold> | ||
| {title} | ||
| </Typography> | ||
| <ul className="flex flex-col"> | ||
| {groupedByCompany?.map(([company, list]) => | ||
| list.length === 1 ? ( | ||
| <UserExperienceItem key={list[0].id} experience={list[0]} /> | ||
| ) : ( | ||
| <UserExperiencesGroupedList | ||
| key={company} | ||
| company={company} | ||
| experiences={list} | ||
| /> | ||
| ), | ||
| )} | ||
| </ul> | ||
| </div> | ||
| ); | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
packages/shared/src/features/profile/components/experience/common.tsx
This file contains hidden or 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,10 @@ | ||
| import React from 'react'; | ||
| import { Pill, PillSize } from '../../../../components/Pill'; | ||
|
|
||
| export const currrentPill = ( | ||
| <Pill | ||
| label="Current" | ||
| size={PillSize.XSmall} | ||
| className="ml-1 border border-border-subtlest-tertiary text-text-secondary" | ||
| /> | ||
| ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need it on FE, doesn't the BE already structure this somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gonna leave for now, but reminder to myself to check later down the line