Skip to content

TCA-787 Link to complete a certification from any lesson -> dev #434

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 4 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export enum UserRole {
gamificationAdmin = 'Gamification Admin',
customer = 'Self-Service Customer',
member = 'Topcoder User',
tcaAdmin = 'TCA Admin',
}
20 changes: 20 additions & 0 deletions src-ts/tools/learn/free-code-camp/FreeCodeCamp.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,23 @@
}
}
}

.wrapBreadcrumb {
position: relative;

.completeCourseBtn {
position: absolute;
right: $space-xxxxl;
bottom: $space-xl;

@include ltesm {
right: $space-sm;
bottom: $space-md;
}

@include md {
right: $space-sm;
bottom: $space-lg;
}
}
}
46 changes: 45 additions & 1 deletion src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@ import {
useState,
} from 'react'
import { NavigateFunction, Params, useNavigate, useParams } from 'react-router-dom'
import { toast, ToastContent } from 'react-toastify'

import {
Breadcrumb,
BreadcrumbItemModel,
Button,
LoadingSpinner,
logError,
profileContext,
ProfileContextData,
surveyTriggerForUser,
textFormatGetSafeString,
UserRole,
} from '../../../lib'
import {
adminCertificationProgressCompleteCourseAsync,
CoursesProviderData,
LearnLesson,
LearnModule,
Expand Down Expand Up @@ -443,10 +448,49 @@ const FreeCodeCamp: FC<{}> = () => {
isLoggedIn,
])

/**
* Complete course shortcut for admins
*/
function adminCompleteCourse(): void {
const confirmed = confirm('Hey, You about to complete the certification. Are you sure?');
if (certificateProgress && confirmed) {
adminCertificationProgressCompleteCourseAsync(certificateProgress.id)
.then(setCertificateProgress)
.then(() => {
toast.info(
<>
<p>Yay, success! You completed the course.</p>
</>
)
})
.catch(error => {
logError(error)
toast.error('Oops! We couldn\'t complete your request as some error happened. See console for more...')
})
}
}

return (
<>
<LoadingSpinner hide={ready} />
<Breadcrumb items={breadcrumb} />
<div className={styles.wrapBreadcrumb}>
<Breadcrumb items={breadcrumb} />
{
lesson
&& profile
&& profile.roles
&& profile.roles.includes(UserRole.tcaAdmin)
&& (
<Button
buttonStyle={'secondary'}
className={styles.completeCourseBtn}
size={'xs'}
label='Complete Course'
onClick={adminCompleteCourse}
/>
)
}
</div>

{lesson && (
<div className={styles['main-wrap']}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './learn-module-status.enum'
export * from './user-certification-progress-status.enum'
export * from './user-certification-update-progress-actions.enum'
export {
adminCompleteCourse as adminCertificationProgressCompleteCourseAsync,
completeCourse as userCertificationProgressCompleteCourseAsync,
startAsync as userCertificationProgressStartAsync,
updateAsync as userCertificationProgressUpdateAsync,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LearnUserCertificationProgress } from './learn-user-certification-progr
import { UserCertificationUpdateProgressActions } from './user-certification-update-progress-actions.enum'

const certProgressPath: string = 'certification-progresses'
const certProgressShortcutPath = 'shortcut-fcc-course-completion'

export function completeCourse(
certificationProgressId: string,
Expand Down Expand Up @@ -53,3 +54,12 @@ export function updateAsync(

return learnXhrPutAsync<{}, LearnUserCertificationProgress>(url, {}, { params: data })
}

export function adminCompleteCourse(
certificationProgressId: string,
): Promise<any> {

const url: string = learnUrlGet(certProgressShortcutPath, certificationProgressId)

return learnXhrPutAsync<{}, any>(url, {})
}
Loading