-
Notifications
You must be signed in to change notification settings - Fork 23
PM-4158 - add completed profiles report page in customer portal #1507
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
3 commits
Select commit
Hold shift + click to select a range
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
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
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
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
114 changes: 114 additions & 0 deletions
114
...rtal/src/pages/profile-completion/ProfileCompletionPage/ProfileCompletionPage.module.scss
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,114 @@ | ||
| @import '@libs/ui/styles/includes'; | ||
|
|
||
| .container { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: $sp-4; | ||
| } | ||
|
|
||
| .headerRow { | ||
| display: flex; | ||
| align-items: flex-end; | ||
| gap: $sp-4; | ||
| justify-content: space-between; | ||
|
|
||
| @include ltemd { | ||
| flex-direction: column; | ||
| align-items: stretch; | ||
| } | ||
| } | ||
|
|
||
| .filterWrap { | ||
| min-width: 280px; | ||
| max-width: 360px; | ||
|
|
||
| @include ltemd { | ||
| max-width: unset; | ||
|
vas3a marked this conversation as resolved.
|
||
| min-width: unset; | ||
| width: 100%; | ||
| } | ||
| } | ||
|
|
||
| .counterCard { | ||
| border: 1px solid $black-20; | ||
| border-radius: $sp-2; | ||
| background: $tc-white; | ||
| padding: $sp-4; | ||
| min-width: 260px; | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: $sp-1; | ||
| } | ||
|
|
||
| .counterLabel { | ||
| color: $black-60; | ||
| font-size: 12px; | ||
| line-height: 16px; | ||
| font-weight: 600; | ||
| text-transform: uppercase; | ||
| } | ||
|
|
||
| .counterValue { | ||
| color: $black-100; | ||
| font-size: 32px; | ||
| line-height: 36px; | ||
| font-weight: 700; | ||
| font-family: 'Nunito Sans', sans-serif; | ||
| } | ||
|
|
||
| .loadingWrap { | ||
| position: relative; | ||
| height: 90px; | ||
|
|
||
| .spinner { | ||
| background: none; | ||
| } | ||
| } | ||
|
|
||
| .errorMessage { | ||
| color: $red-100; | ||
| font-size: 14px; | ||
| line-height: 20px; | ||
| font-weight: 700; | ||
| } | ||
|
|
||
| .emptyMessage { | ||
| color: $black-60; | ||
| font-size: 14px; | ||
| line-height: 20px; | ||
| } | ||
|
|
||
| .tableWrap { | ||
| overflow: auto; | ||
| border: 1px solid $black-20; | ||
| border-radius: $sp-2; | ||
|
|
||
| table { | ||
| width: 100%; | ||
| border-collapse: collapse; | ||
| min-width: 420px; | ||
| } | ||
|
|
||
| th, | ||
| td { | ||
| text-align: left; | ||
| padding: $sp-3 $sp-4; | ||
| border-bottom: 1px solid $black-20; | ||
| font-size: 14px; | ||
| line-height: 20px; | ||
| } | ||
|
|
||
| th { | ||
| color: $black-100; | ||
| font-weight: 700; | ||
| background: $black-5; | ||
| } | ||
|
|
||
| td { | ||
| color: $black-100; | ||
| } | ||
|
|
||
| tr:last-child td { | ||
| border-bottom: 0; | ||
| } | ||
| } | ||
189 changes: 189 additions & 0 deletions
189
...tomer-portal/src/pages/profile-completion/ProfileCompletionPage/ProfileCompletionPage.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,189 @@ | ||
| /* eslint-disable react/jsx-no-bind */ | ||
|
vas3a marked this conversation as resolved.
|
||
| import { ChangeEvent, FC, useMemo, useState } from 'react' | ||
| import useSWR, { SWRResponse } from 'swr' | ||
|
|
||
| import { EnvironmentConfig } from '~/config' | ||
| import { CountryLookup, useCountryLookup, xhrGetAsync } from '~/libs/core' | ||
| import { InputSelect, InputSelectOption, LoadingSpinner } from '~/libs/ui' | ||
|
|
||
| import { PageWrapper } from '../../../lib' | ||
|
|
||
| import styles from './ProfileCompletionPage.module.scss' | ||
|
|
||
| type CompletedProfile = { | ||
| countryCode?: string | ||
| countryName?: string | ||
| handle: string | ||
| userId?: number | string | ||
| } | ||
|
|
||
| function normalizeToList(raw: any): any[] { | ||
|
vas3a marked this conversation as resolved.
|
||
| if (Array.isArray(raw)) { | ||
| return raw | ||
| } | ||
|
|
||
| if (Array.isArray(raw?.data)) { | ||
| return raw.data | ||
| } | ||
|
|
||
| if (Array.isArray(raw?.result?.content)) { | ||
| return raw.result.content | ||
| } | ||
|
|
||
| if (Array.isArray(raw?.result)) { | ||
| return raw.result | ||
| } | ||
|
|
||
| return [] | ||
| } | ||
|
|
||
| async function fetchCompletedProfiles(): Promise<CompletedProfile[]> { | ||
| const response = await xhrGetAsync<CompletedProfile[]>( | ||
| `${EnvironmentConfig.REPORTS_API}/topcoder/completed-profiles`, | ||
| ) | ||
|
|
||
| return normalizeToList(response) | ||
| } | ||
|
|
||
| export const ProfileCompletionPage: FC = () => { | ||
| const [selectedCountry, setSelectedCountry] = useState<string>('all') | ||
| const countryLookup: CountryLookup[] | undefined = useCountryLookup() | ||
|
|
||
| const { data, error, isValidating }: SWRResponse<CompletedProfile[]> = useSWR( | ||
| 'customer-portal-completed-profiles', | ||
| fetchCompletedProfiles, | ||
| { | ||
| revalidateOnFocus: false, | ||
| }, | ||
| ) | ||
|
|
||
| const countryMap = useMemo(() => { | ||
| const map = new Map<string, string>(); | ||
| (countryLookup || []).forEach(country => { | ||
| if (country.countryCode) { | ||
| map.set(country.countryCode, country.country) | ||
| } | ||
| }) | ||
|
|
||
| return map | ||
| }, [countryLookup]) | ||
|
|
||
| const countryOptions = useMemo<InputSelectOption[]>(() => { | ||
| const dynamicCodes = new Set<string>(); | ||
| (data || []).forEach(profile => { | ||
| if (profile.countryCode) { | ||
| dynamicCodes.add(profile.countryCode) | ||
| } | ||
| }) | ||
|
|
||
| const dynamicOptions = Array.from(dynamicCodes) | ||
| .map(code => ({ | ||
| label: countryMap.get(code) || code, | ||
| value: code, | ||
| })) | ||
| .sort((a, b) => String(a.label) | ||
| .localeCompare(String(b.label))) | ||
|
|
||
| return [ | ||
| { | ||
| label: 'All Countries', | ||
| value: 'all', | ||
| }, | ||
| ...dynamicOptions, | ||
| ] | ||
| }, [countryMap, data]) | ||
|
|
||
| const profiles = useMemo(() => { | ||
| const source = data || [] | ||
| if (selectedCountry === 'all') { | ||
| return source | ||
| } | ||
|
|
||
| return source.filter(profile => profile.countryCode === selectedCountry) | ||
| }, [data, selectedCountry]) | ||
|
|
||
| const displayedRows = useMemo(() => profiles | ||
| .map(profile => ({ | ||
| ...profile, | ||
| countryLabel: profile.countryCode | ||
| ? countryMap.get(profile.countryCode) || profile.countryName || profile.countryCode | ||
| : profile.countryName || '-', | ||
| })) | ||
| .sort((a, b) => a.handle.localeCompare(b.handle)), [profiles, countryMap]) | ||
|
|
||
| return ( | ||
| <PageWrapper | ||
| pageTitle='Profile Completion' | ||
| breadCrumb={[]} | ||
| className={styles.container} | ||
| > | ||
| <div className={styles.headerRow}> | ||
| <div className={styles.filterWrap}> | ||
| <InputSelect | ||
| name='country' | ||
| label='Country' | ||
| options={countryOptions} | ||
| value={selectedCountry} | ||
| onChange={(event: ChangeEvent<HTMLInputElement>) => { | ||
| setSelectedCountry(event.target.value || 'all') | ||
|
vas3a marked this conversation as resolved.
|
||
| }} | ||
| placeholder='Select country' | ||
| /> | ||
| </div> | ||
| <div className={styles.counterCard}> | ||
| <span className={styles.counterLabel}>Fully Completed Profiles</span> | ||
| <strong className={styles.counterValue}>{profiles.length}</strong> | ||
| </div> | ||
| </div> | ||
|
|
||
| {isValidating && !data && ( | ||
| <div className={styles.loadingWrap}> | ||
| <LoadingSpinner className={styles.spinner} /> | ||
| </div> | ||
| )} | ||
|
|
||
| {!isValidating && !!error && ( | ||
| <div className={styles.errorMessage}> | ||
| Failed to load profile completion data. | ||
| </div> | ||
| )} | ||
|
|
||
| {!error && !isValidating && displayedRows.length === 0 && ( | ||
| <div className={styles.emptyMessage}> | ||
| No fully completed profiles found for the selected country. | ||
| </div> | ||
| )} | ||
|
|
||
| {!error && displayedRows.length > 0 && ( | ||
| <div className={styles.tableWrap}> | ||
| <table> | ||
| <thead> | ||
| <tr> | ||
| <th>Handle</th> | ||
| <th>Country</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {displayedRows.map(profile => ( | ||
| <tr key={profile.userId || profile.handle}> | ||
|
vas3a marked this conversation as resolved.
|
||
| <td> | ||
| <a | ||
| href={`${EnvironmentConfig.USER_PROFILE_URL}/${profile.handle}`} | ||
| target='_blank' | ||
| rel='noreferrer noopener' | ||
| > | ||
| {profile.handle} | ||
| </a> | ||
| </td> | ||
| <td>{profile.countryLabel}</td> | ||
| </tr> | ||
| ))} | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| )} | ||
| </PageWrapper> | ||
| ) | ||
| } | ||
|
|
||
| export default ProfileCompletionPage | ||
1 change: 1 addition & 0 deletions
1
src/apps/customer-portal/src/pages/profile-completion/ProfileCompletionPage/index.ts
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 @@ | ||
| export { default as ProfileCompletionPage } from './ProfileCompletionPage' |
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 @@ | ||
| export * from './ProfileCompletionPage' | ||
|
vas3a marked this conversation as resolved.
|
||
26 changes: 26 additions & 0 deletions
26
src/apps/customer-portal/src/pages/profile-completion/profile-completion.routes.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,26 @@ | ||
| import { getRoutesContainer, lazyLoad, LazyLoadedComponent } from '~/libs/core' | ||
|
|
||
| import { profileCompletionRouteId } from '../../config/routes.config' | ||
|
|
||
| const ProfileCompletionPage: LazyLoadedComponent = lazyLoad( | ||
| () => import('./ProfileCompletionPage'), | ||
| 'ProfileCompletionPage', | ||
| ) | ||
|
|
||
| export const profileCompletionChildRoutes = [ | ||
| { | ||
| authRequired: true, | ||
| element: <ProfileCompletionPage />, | ||
| id: 'profile-completion-page', | ||
| route: '', | ||
|
vas3a marked this conversation as resolved.
|
||
| }, | ||
| ] | ||
|
|
||
| export const customerPortalProfileCompletionRoutes = [ | ||
| { | ||
| children: [...profileCompletionChildRoutes], | ||
| element: getRoutesContainer(profileCompletionChildRoutes), | ||
| id: profileCompletionRouteId, | ||
| route: profileCompletionRouteId, | ||
| }, | ||
| ] | ||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.