Skip to content
Merged
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
29 changes: 29 additions & 0 deletions src-ts/lib/functions/error-functions/error.functions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Link } from 'react-router-dom'
import { toast, ToastContent } from 'react-toastify'

import { contactSupportPath } from '../../contact-support-form'
import { logError } from '../logging-functions'

export function handle(error: any, errString?: string): void {

logError(error)

const errorContent: ToastContent = (
<>
<p>
{errString ?? error.response?.data?.result?.content ?? error.message ?? error}
{' '}
Please try again later or
{' '}
<Link
className='font-link-blue-dark'
to={contactSupportPath}
>
Contact Support
</Link>.
</p>
</>
)

toast.error(errorContent)
}
1 change: 1 addition & 0 deletions src-ts/lib/functions/error-functions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { handle as errorHandle } from './error.functions'
1 change: 1 addition & 0 deletions src-ts/lib/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export {
authUrlLogout,
authUrlSignup,
} from './authentication-functions'
export * from './error-functions'
export * from './file-functions'
export * from './logging-functions'
export * from './text-format-functions'
Expand Down
3 changes: 3 additions & 0 deletions src-ts/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ export {
authUrl,
authUrlLogin,
authUrlLogout,
authUrlSignup,
errorHandle,
fileCreateFromCanvas,
fileDownloadBlob,
fileDownloadCanvasAsImage,
logError,
logInfo,
logInitialize,
textFormatDateLocaleShortString,
Expand Down
11 changes: 8 additions & 3 deletions src-ts/lib/loading-spinner/LoadingSpinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ import styles from './LoadingSpinner.module.scss'

export interface LoadingSpinnerProps {
className?: string
show?: boolean
hide?: boolean
}

const LoadingSpinner: FC<LoadingSpinnerProps> = ({ show = false, className }: LoadingSpinnerProps) => {
const LoadingSpinner: FC<LoadingSpinnerProps> = ({ hide, className }: LoadingSpinnerProps) => {

if (!!hide) {
return <></>
}

return (
<div className={classNames(styles['loading-spinner'], styles[show ? 'show' : 'hide'], className)}>
<div className={classNames(styles['loading-spinner'], styles.show, className)}>
<PuffLoader color={'#2196f3'} loading={true} size={100} />
</div>
)
Expand Down
14 changes: 12 additions & 2 deletions src-ts/lib/styles/_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,27 @@ hr {
display: none;
}

.full-height-frame {
position: relative;
flex: 1 1 auto;
display: flex;
flex-direction: column;
}

.mobile-hide {
&.mobile-hide.mobile-hide { // increase specificity without using !important

// increase specificity without using !important
&.mobile-hide.mobile-hide {
@include ltemd {
display: none;
}
}
}

.desktop-hide {
&.desktop-hide.desktop-hide { // increase specificity without using !important

// increase specificity without using !important
&.desktop-hide.desktop-hide {
@include gtelg {
display: none;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const CertificateView: FC<CertificateViewProps> = (props: CertificateViewProps)

return (
<>
{!ready && <LoadingSpinner show />}
<LoadingSpinner hide={ready} />

{readyAndCompletedCertification && (
<div className={styles['wrap']}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ const MyCertificate: FC<{}> = () => {
}, [coursePath, navigate])

useEffect(() => {
if (profileReady && !profile) {
navigateToCourse()
}
if (profileReady && !profile) {
navigateToCourse()
}
}, [profileReady, profile, navigateToCourse])

return (
<>
{!profileReady && <LoadingSpinner show />}
<LoadingSpinner hide={profileReady} />

{profileReady && profile && (
<CertificateView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,25 @@ import CertificateView from '../certificate-view/CertificateView'
import styles from './UserCertificate.module.scss'

const UserCertificate: FC<{}> = () => {

const wrapElRef: MutableRefObject<HTMLElement | any> = useRef()
const routeParams: Params<string> = useParams()
const [profile, setProfile]: [
UserProfile|undefined,
Dispatch<SetStateAction<UserProfile|undefined>>
UserProfile | undefined,
Dispatch<SetStateAction<UserProfile | undefined>>
] = useState()
const [profileReady, setProfileReady]: [boolean, Dispatch<SetStateAction<boolean>>] = useState(false)
const [profileReady, setProfileReady]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)

const providerParam: string = routeParams.provider ?? ''
const certificationParam: string = routeParams.certification ?? ''

useEffect(() => {
if (routeParams.memberHandle) {
profileGetAsync(routeParams.memberHandle).then((userProfile) => {
setProfile(userProfile)
setProfileReady(true)
})
profileGetAsync(routeParams.memberHandle)
.then((userProfile) => {
setProfile(userProfile)
setProfileReady(true)
})
}
}, [routeParams.memberHandle, setProfileReady])

Expand All @@ -39,23 +41,23 @@ const UserCertificate: FC<{}> = () => {

[].forEach.call(el.parentElement?.children ?? [], (c: HTMLElement) => {
if (c !== el) {
Object.assign(c.style, {display: 'none'})
Object.assign(c.style, { display: 'none' })
}
})
el.classList.add(styles['full-screen-cert'])
})

return (
<>
{!profileReady && <LoadingSpinner show />}
<LoadingSpinner hide={profileReady} />

{profileReady && profile && (
<div ref={wrapElRef}>
<CertificateView
certification={certificationParam}
profile={profile}
provider={providerParam}
onCertificationNotCompleted={() => {}}
onCertificationNotCompleted={() => { }}
hideActions
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const CourseCompletedPage: FC<{}> = () => {

return (
<>
{!ready && <LoadingSpinner show />}
<LoadingSpinner hide={ready} />

{ready && courseData && (
<>
Expand Down
2 changes: 1 addition & 1 deletion src-ts/tools/learn/course-details/CourseDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const CourseDetailsPage: FC<{}> = () => {
<ContentLayout>
{!ready && (
<div className={styles['wrap']}>
<LoadingSpinner show />
<LoadingSpinner />
</div>
)}
<Breadcrumb items={breadcrumb} />
Expand Down
2 changes: 1 addition & 1 deletion src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ const FreeCodeCamp: FC<{}> = () => {

return (
<>
{!ready && <LoadingSpinner show />}
<LoadingSpinner hide={ready} />
<Breadcrumb items={breadcrumb} />

{lesson && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const CourseOutline: FC<CourseOutlineProps> = (props: CourseOutlineProps) => {

return (
<div className={classNames(styles['wrap'], 'course-outline-wrap')}>
{props.ready === false && <LoadingSpinner show />}

<LoadingSpinner hide={props.ready !== false} />

{props.course && (
<div className={classNames(styles['content'], 'content')}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Dispatch, SetStateAction, useContext, useEffect, useState } from 'react'

import { profileContext, ProfileContextData } from '../../../../lib'
import { errorHandle, profileContext, ProfileContextData } from '../../../../lib'

import { UserCertificationCompleted } from './user-certification-completed.model'
import { UserCertificationInProgress } from './user-certification-in-progress.model'
Expand Down Expand Up @@ -64,6 +64,16 @@ export function useUserCertifications(): UserCertificationsProviderData {
ready: true,
}))
})
.catch((err: any) => {
errorHandle(err, 'There was an error getting your course progress.')
setState((prevState) => ({
...prevState,
completed: [],
inProgress: [],
loading: false,
ready: true,
}))
})

return () => {
mounted = false
Expand Down
14 changes: 9 additions & 5 deletions src-ts/tools/learn/welcome/WelcomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import classNames from 'classnames'
import { FC } from 'react'

import { ContentLayout, LoadingSpinner, Portal } from '../../../lib'
import '../../../lib/styles/index.scss'
import {
AllCertificationsProviderData,
useAllCertifications,
Expand All @@ -22,7 +24,9 @@ const WelcomePage: FC<{}> = () => {

return (
<ContentLayout>
<div className={styles.wrap}>

<div className={classNames(styles.wrap, 'full-height-frame')}>

<Portal portalId='page-subheader-portal-el'>
<div className={styles['hero-wrap']}>
<WaveHero
Expand All @@ -47,11 +51,11 @@ const WelcomePage: FC<{}> = () => {
</div>
</Portal>

<div className={styles['courses-section']}>
<div className={classNames(styles['courses-section'], 'full-height-frame')}>

<h3 className='details'>Courses Available</h3>
{!coursesReady && (
<LoadingSpinner show />
)}

<LoadingSpinner hide={coursesReady} />

{coursesReady && (
<div className={styles['courses-list']}>
Expand Down
2 changes: 1 addition & 1 deletion src-ts/tools/work/Work.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Work: FC<{}> = () => {

// if the profile isn't initialized, wait with the spinner
if (!initialized) {
return <LoadingSpinner show={true} />
return <LoadingSpinner />
}

// if the profile is initialized, go to the self-service login
Expand Down
6 changes: 3 additions & 3 deletions src-ts/tools/work/work-lib/work-provider/work.provider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Dispatch, FC, ReactNode, SetStateAction, useContext, useEffect, useState } from 'react'

import { profileContext, ProfileContextData, UserProfile } from '../../../../lib'
import { logError, profileContext, ProfileContextData, UserProfile } from '../../../../lib'

import { WorkContextData } from './work-context-data.model'
import { Work, workGetAllAsync, } from './work-functions'
Expand Down Expand Up @@ -33,12 +33,12 @@ export const WorkProvider: FC<{ children: ReactNode }> = ({ children }: { childr
setWorkContextData(contextData)

} catch (error: any) {
logError(error)
const contextData: WorkContextData = {
...defaultWorkContextData,
error: error.response?.data?.result?.content || error.message || error,
hasWork: false,
initialized: true,
refresh: getAndSetWork,
work: [],
}
setWorkContextData(contextData)
}
Expand Down
2 changes: 1 addition & 1 deletion src-ts/tools/work/work-not-logged-in/WorkNotLoggedIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const WorkNotLoggedIn: FC<{}> = () => {
}, [isLoggedIn, initialized, navigate])

if (isLoading) {
return <LoadingSpinner show={true} />
return <LoadingSpinner />
}

function startWork(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ const Review: FC = () => {

return (
<div className={styles['review-container']}>
<LoadingSpinner show={isLoading} />
<LoadingSpinner hide={!isLoading} />
{/* TODO: We need to not hard code the configs to that of BugHunt and instead
use the challenge data to determine the WorkType */}
<IntakeFormsBreadcrumb
Expand Down
4 changes: 0 additions & 4 deletions src-ts/tools/work/work-table/WorkTable.module.scss

This file was deleted.

4 changes: 2 additions & 2 deletions src-ts/tools/work/work-table/WorkTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
TabsNavbar,
TabsNavItem,
} from '../../../lib'
import '../../../lib/styles/index.scss'
import {
Work,
WorkByStatus,
Expand All @@ -27,7 +28,6 @@ import { dashboardRoute, selfServiceStartRoute, workDetailRoute } from '../work.
import { workDashboardTabs } from './work-nav.config'
import { WorkNoResults } from './work-no-results'
import { WorkListColumnField, workListColumns } from './work-table.config'
import styles from './WorkTable.module.scss'

const WorkTable: FC<{}> = () => {

Expand Down Expand Up @@ -131,7 +131,7 @@ const WorkTable: FC<{}> = () => {
return (
<>
{tabsElement}
<div className={styles.loader}>
<div className='full-height-frame'>
<LoadingSpinner />
</div>
</>
Expand Down
Loading