Skip to content

Commit 9427358

Browse files
Merge pull request #434 from topcoder-platform/TCA-787
TCA-787 Link to complete a certification from any lesson -> dev
2 parents 812782a + 932f0d3 commit 9427358

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
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
@@ -47,3 +47,23 @@
4747
}
4848
}
4949
}
50+
51+
.wrapBreadcrumb {
52+
position: relative;
53+
54+
.completeCourseBtn {
55+
position: absolute;
56+
right: $space-xxxxl;
57+
bottom: $space-xl;
58+
59+
@include ltesm {
60+
right: $space-sm;
61+
bottom: $space-md;
62+
}
63+
64+
@include md {
65+
right: $space-sm;
66+
bottom: $space-lg;
67+
}
68+
}
69+
}

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ import {
1111
useState,
1212
} from 'react'
1313
import { NavigateFunction, Params, useNavigate, useParams } from 'react-router-dom'
14+
import { toast, ToastContent } from 'react-toastify'
1415

1516
import {
1617
Breadcrumb,
1718
BreadcrumbItemModel,
19+
Button,
1820
LoadingSpinner,
21+
logError,
1922
profileContext,
2023
ProfileContextData,
2124
surveyTriggerForUser,
2225
textFormatGetSafeString,
26+
UserRole,
2327
} from '../../../lib'
2428
import {
2529
CoursesProviderData,
@@ -33,6 +37,7 @@ import {
3337
useGetLesson,
3438
useGetUserCertificationProgress,
3539
useLearnBreadcrumb,
40+
userCertificationProgressAutocompleteCourse,
3641
userCertificationProgressCompleteCourseAsync,
3742
UserCertificationProgressProviderData,
3843
userCertificationProgressStartAsync,
@@ -467,10 +472,44 @@ const FreeCodeCamp: FC<{}> = () => {
467472
certificationParam,
468473
]);
469474

475+
/**
476+
* Complete course shortcut for admins
477+
*/
478+
function adminCompleteCourse(): void {
479+
const confirmed = confirm('Hey, you\'re about to auto-complete this entire course. Are you sure?');
480+
481+
if (!certificateProgress?.id || !confirmed) {
482+
return
483+
}
484+
485+
userCertificationProgressAutocompleteCourse(certificateProgress.id)
486+
.then(setCertificateProgress)
487+
.then(() => {
488+
toast.info(<p>Yay, success! You completed the course.</p>)
489+
})
490+
.catch(error => {
491+
logError(error)
492+
toast.error('Oops! We couldn\'t complete your request as some error happened. See console for more...')
493+
})
494+
}
495+
470496
return (
471497
<>
472498
<LoadingSpinner hide={ready} />
473-
<Breadcrumb items={breadcrumb} />
499+
<div className={styles.wrapBreadcrumb}>
500+
<Breadcrumb items={breadcrumb} />
501+
{
502+
lesson && profile?.roles?.includes(UserRole.tcaAdmin) && (
503+
<Button
504+
buttonStyle='secondary'
505+
className={styles.completeCourseBtn}
506+
size='xs'
507+
label='Complete Course'
508+
onClick={adminCompleteCourse}
509+
/>
510+
)
511+
}
512+
</div>
474513

475514
{lesson && (
476515
<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 userCertificationProgressAutocompleteCourse,
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)