Skip to content

Commit bc73636

Browse files
committed
TCA-787 complete a certification shortcut
1 parent 9fc1e01 commit bc73636

File tree

6 files changed

+1733
-1465
lines changed

6 files changed

+1733
-1465
lines changed

src-ts/lib/profile-provider/profile-functions/profile-factory/user-role.enum.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export enum UserRole {
22
gamificationAdmin = 'Gamification Admin',
33
customer = 'Self-Service Customer',
44
member = 'Topcoder User',
5+
tcaAdmin = 'TCA Admin',
56
}

src-ts/tools/learn/free-code-camp/FreeCodeCamp.module.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,23 @@
4848
}
4949
}
5050
}
51+
52+
.wrapBreadcrumb {
53+
position: relative;
54+
55+
.completeCourseBtn {
56+
position: absolute;
57+
right: $space-xxxxl;
58+
bottom: $space-xl;
59+
60+
@include ltesm {
61+
right: $space-sm;
62+
bottom: $space-md;
63+
}
64+
65+
@include md {
66+
right: $space-sm;
67+
bottom: $space-lg;
68+
}
69+
}
70+
}

src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,22 @@ import {
1010
useState,
1111
} from 'react'
1212
import { NavigateFunction, Params, useNavigate, useParams } from 'react-router-dom'
13+
import { toast, ToastContent } from 'react-toastify'
1314

1415
import {
1516
Breadcrumb,
1617
BreadcrumbItemModel,
18+
Button,
1719
LoadingSpinner,
20+
logError,
1821
profileContext,
1922
ProfileContextData,
2023
surveyTriggerForUser,
2124
textFormatGetSafeString,
25+
UserRole,
2226
} from '../../../lib'
2327
import {
28+
adminCertificationProgressCompleteCourseAsync,
2429
CoursesProviderData,
2530
LearnLesson,
2631
LearnModule,
@@ -443,10 +448,49 @@ const FreeCodeCamp: FC<{}> = () => {
443448
isLoggedIn,
444449
])
445450

451+
/**
452+
* Complete course shortcut for admins
453+
*/
454+
function adminCompleteCourse(): void {
455+
const confirmed = confirm('Hey, You about to complete the certification. Are you sure?');
456+
if (certificateProgress && confirmed) {
457+
adminCertificationProgressCompleteCourseAsync(certificateProgress.id)
458+
.then(setCertificateProgress)
459+
.then(() => {
460+
toast.info(
461+
<>
462+
<p>Yay, success! You completed the course.</p>
463+
</>
464+
)
465+
})
466+
.catch(error => {
467+
logError(error)
468+
toast.error('Oops! We couldn\'t complete your request as some error happened. See console for more...')
469+
})
470+
}
471+
}
472+
446473
return (
447474
<>
448475
<LoadingSpinner hide={ready} />
449-
<Breadcrumb items={breadcrumb} />
476+
<div className={styles.wrapBreadcrumb}>
477+
<Breadcrumb items={breadcrumb} />
478+
{
479+
lesson
480+
&& profile
481+
&& profile.roles
482+
&& profile.roles.includes(UserRole.tcaAdmin)
483+
&& (
484+
<Button
485+
buttonStyle={'secondary'}
486+
className={styles.completeCourseBtn}
487+
size={'xs'}
488+
label='Complete Course'
489+
onClick={adminCompleteCourse}
490+
/>
491+
)
492+
}
493+
</div>
450494

451495
{lesson && (
452496
<div className={styles['main-wrap']}>

src-ts/tools/learn/learn-lib/data-providers/user-certifications-provider/user-certifications-functions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export * from './learn-module-status.enum'
44
export * from './user-certification-progress-status.enum'
55
export * from './user-certification-update-progress-actions.enum'
66
export {
7+
adminCompleteCourse as adminCertificationProgressCompleteCourseAsync,
78
completeCourse as userCertificationProgressCompleteCourseAsync,
89
startAsync as userCertificationProgressStartAsync,
910
updateAsync as userCertificationProgressUpdateAsync,

src-ts/tools/learn/learn-lib/data-providers/user-certifications-provider/user-certifications-functions/user-certification-progress.store.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { LearnUserCertificationProgress } from './learn-user-certification-progr
77
import { UserCertificationUpdateProgressActions } from './user-certification-update-progress-actions.enum'
88

99
const certProgressPath: string = 'certification-progresses'
10+
const certProgressShortcutPath = 'shortcut-fcc-course-completion'
1011

1112
export function completeCourse(
1213
certificationProgressId: string,
@@ -53,3 +54,12 @@ export function updateAsync(
5354

5455
return learnXhrPutAsync<{}, LearnUserCertificationProgress>(url, {}, { params: data })
5556
}
57+
58+
export function adminCompleteCourse(
59+
certificationProgressId: string,
60+
): Promise<any> {
61+
62+
const url: string = learnUrlGet(certProgressShortcutPath, certificationProgressId)
63+
64+
return learnXhrPutAsync<{}, any>(url, {})
65+
}

0 commit comments

Comments
 (0)