-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib-user: Add certificate page (#6124)
* Move AuthenticatedUsersPageContainer * Initial Certificate page * Add CertificateContainer, refactor styling * Refactor Layout and PageHeader media print styling * Add Certificate page box-shadow, refactor borders * Refactor Box flex for printing * Format ContentLink when button * Refactor Certificate date range * Update test descriptions * Refactor Generate Volunteer Certificate link * Refactor lib-user UserStats and Certificate containers for selectedDateRange and selectedProject as props * Create app-root UserStatsContext and UserStatsContextProvider * Refactor app-root UserStats and Certificate containers with UserStats context * Refactor lib-user dev app * Update lib-react-components CHANGELOG and add comments for print display none styling * Refactor user stats dateRange and project hooks to localStorage for persistence across browser tabs * Clean up * Reset user stats dateRange and project context on sign-out * Update packages/lib-user/src/components/Certificate/Certificate.js * Fix Tab color contrast issue * Refactor Generate Volunteer Certificate button * Add svg gradient line under signature img
- Loading branch information
Showing
39 changed files
with
735 additions
and
44 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
35 changes: 35 additions & 0 deletions
35
packages/app-root/src/app/users/[login]/stats/certificate/CertificateContainer.js
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 @@ | ||
'use client' | ||
|
||
import { Certificate } from '@zooniverse/user' | ||
import { useContext } from 'react' | ||
|
||
import { PanoptesAuthContext, UserStatsContext } from '../../../../../contexts' | ||
import AuthenticatedUsersPageContainer from '../../../../../components/AuthenticatedUsersPageContainer' | ||
|
||
function CertificateContainer({ | ||
login | ||
}) { | ||
const { adminMode, isLoading, user } = useContext(PanoptesAuthContext) | ||
const { | ||
selectedDateRange, | ||
selectedProject | ||
} = useContext(UserStatsContext) | ||
|
||
return ( | ||
<AuthenticatedUsersPageContainer | ||
adminMode={adminMode} | ||
isLoading={isLoading} | ||
login={login} | ||
user={user} | ||
> | ||
<Certificate | ||
authUser={user} | ||
login={login} | ||
selectedDateRange={selectedDateRange} | ||
selectedProject={selectedProject} | ||
/> | ||
</AuthenticatedUsersPageContainer> | ||
) | ||
} | ||
|
||
export default CertificateContainer |
14 changes: 14 additions & 0 deletions
14
packages/app-root/src/app/users/[login]/stats/certificate/page.js
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,14 @@ | ||
import CertificateContainer from './CertificateContainer' | ||
|
||
export const metadata = { | ||
title: 'Certificate', | ||
description: 'My Zooniverse certificate page' | ||
} | ||
|
||
export default function Certificate({ params }) { | ||
return ( | ||
<CertificateContainer | ||
login={params.login} | ||
/> | ||
) | ||
} |
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,9 @@ | ||
import UserStatsContextProvider from '../../../../components/UserStatsContextProvider' | ||
|
||
export default function UserStatsLayout({ children }) { | ||
return ( | ||
<UserStatsContextProvider> | ||
{children} | ||
</UserStatsContextProvider> | ||
) | ||
} |
File renamed without changes.
27 changes: 27 additions & 0 deletions
27
packages/app-root/src/components/UserStatsContextProvider.js
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,27 @@ | ||
'use client' | ||
|
||
import { useContext } from 'react' | ||
|
||
import { PanoptesAuthContext, UserStatsContext } from '../contexts' | ||
import { useStatsDateRange, useStatsProject } from '../hooks' | ||
|
||
function UserStatsContextProvider({ children }) { | ||
const { isLoading, user } = useContext(PanoptesAuthContext) | ||
const { selectedDateRange, setSelectedDateRange } = useStatsDateRange({ isLoading, user }) | ||
const { selectedProject, setSelectedProject } = useStatsProject({ isLoading, user }) | ||
|
||
const statsContext = { | ||
selectedDateRange, | ||
selectedProject, | ||
setSelectedDateRange, | ||
setSelectedProject | ||
} | ||
|
||
return ( | ||
<UserStatsContext.Provider value={statsContext}> | ||
{children} | ||
</UserStatsContext.Provider> | ||
) | ||
} | ||
|
||
export default UserStatsContextProvider |
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,5 @@ | ||
import { createContext } from 'react' | ||
|
||
const UserStatsContext = createContext({}) | ||
|
||
export default UserStatsContext |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as PanoptesAuthContext } from './PanoptesAuthContext.js' | ||
export { default as ThemeModeContext } from './ThemeModeContext.js' | ||
export { default as UserStatsContext } from './UserStatsContext.js' |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export { default as useAdminMode } from './useAdminMode.js' | ||
export { default as usePreferredTheme } from './usePreferredTheme.js' | ||
export { default as useStatsDateRange } from './useStatsDateRange.js' | ||
export { default as useStatsProject } from './useStatsProject.js' |
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,26 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
const isBrowser = typeof window !== 'undefined' | ||
const localStorage = isBrowser ? window.localStorage : null | ||
|
||
let initialDateRange = 'Last7Days' | ||
if (isBrowser) { | ||
initialDateRange = localStorage?.getItem('selectedDateRange') || initialDateRange | ||
} | ||
|
||
export default function useStatsDateRange({ isLoading, user }) { | ||
const [selectedDateRange, setSelectedDateRange] = useState(initialDateRange) | ||
|
||
useEffect(function onDateRangeChange() { | ||
localStorage?.setItem('selectedDateRange', selectedDateRange) | ||
}, [selectedDateRange]) | ||
|
||
useEffect(function onUserChange() { | ||
// when a user successfully logs out isLoading is false and user is undefined | ||
if (!isLoading && !user?.login) { | ||
setSelectedDateRange('Last7Days') | ||
} | ||
}, [isLoading, user?.login]) | ||
|
||
return { selectedDateRange, setSelectedDateRange } | ||
} |
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,26 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
const isBrowser = typeof window !== 'undefined' | ||
const localStorage = isBrowser ? window.localStorage : null | ||
|
||
let initialProject = 'AllProjects' | ||
if (isBrowser) { | ||
initialProject = localStorage?.getItem('selectedProject') || initialProject | ||
} | ||
|
||
export default function useStatsProject({ isLoading, user }) { | ||
const [selectedProject, setSelectedProject] = useState(initialProject) | ||
|
||
useEffect(function onProjectChange() { | ||
localStorage?.setItem('selectedProject', selectedProject) | ||
}, [selectedProject]) | ||
|
||
useEffect(function onUserChange() { | ||
// when a user successfully logs out isLoading is false and user is undefined | ||
if (!isLoading && !user?.login) { | ||
setSelectedProject('AllProjects') | ||
} | ||
}, [isLoading, user?.login]) | ||
|
||
return { selectedProject, setSelectedProject } | ||
} |
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
Oops, something went wrong.