Skip to content

Commit

Permalink
notify locked users when they complete all their subjects
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronshiel committed Sep 28, 2023
1 parent 35e3f98 commit a537195
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
3 changes: 3 additions & 0 deletions client/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ export async function fetchUsers(
disableKeywordsRecommendation
disableThumbnailRecommendation
disableLevelProgressDisplay
completeSubjectsNotificationText
}
orgPermissions {
orgId
Expand Down Expand Up @@ -1078,6 +1079,7 @@ export async function fetchMentorById(
disableKeywordsRecommendation
disableThumbnailRecommendation
disableLevelProgressDisplay
completeSubjectsNotificationText
}
orgPermissions {
orgId
Expand Down Expand Up @@ -1253,6 +1255,7 @@ export async function fetchMentorConfig(
disableKeywordsRecommendation
disableThumbnailRecommendation
disableLevelProgressDisplay
completeSubjectsNotificationText
}
}
`,
Expand Down
32 changes: 31 additions & 1 deletion client/src/components/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ function HomePage(props: {
const mentorConfig: MentorConfig | undefined = getData(
(m) => m.data?.mentorConfig
);
const lockedToConfig: boolean = getData((m) => m.data?.lockedToConfig);
const defaultMentor = props.user.defaultMentor._id;
const { classes } = useStyles();
const [showSetupAlert, setShowSetupAlert] = useState(true);
Expand Down Expand Up @@ -190,7 +191,8 @@ function HomePage(props: {
useState<ConfirmSave>();
const [confirmSaveOnRecordOne, setConfirmSaveOnRecordOne] =
useState<ConfirmSave>();

const [notifyCompleteAllQuestions, setNotifyCompleteAllQuestions] =
useState<boolean>(false);
const loginState = useWithLogin();

const [localHasSeenSplash, setLocalHasSeenSplash] = useState(false);
Expand Down Expand Up @@ -273,6 +275,26 @@ function HomePage(props: {
mentorId,
]);

useEffect(() => {
const lockedToSubjects = mentorConfig?.subjects.length;
if (
!lockedToConfig ||
!mentorConfig ||
!lockedToSubjects ||
!mentorConfig.completeSubjectsNotificationText
) {
return;
}
if (
reviewAnswerState.progress.total != 0 &&
reviewAnswerState.progress.complete ===
reviewAnswerState.progress.total &&
!notifyCompleteAllQuestions
) {
setNotifyCompleteAllQuestions(true);
}
}, [reviewAnswerState.progress, mentorConfig, lockedToConfig]);

// memoized train mentor
const startTrainingMentor = useCallback(() => {
startTraining(mentorId);
Expand Down Expand Up @@ -745,6 +767,14 @@ function HomePage(props: {
</DialogContent>
</Dialog>

<NotificationDialog
title={mentorConfig?.completeSubjectsNotificationText}
open={notifyCompleteAllQuestions}
closeDialog={() => {
setNotifyCompleteAllQuestions(false);
}}
/>

<TwoOptionDialog
open={Boolean(confirmSaveBeforeCallback)}
title={confirmSaveBeforeCallback?.message || ""}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ function MentorStatus(props: {
const mentorInfo = getData((ms) =>
ms.data ? parseMentor(ms.data, allQuestions) : defaultMentorInfo
);
const mentorConfig: MentorConfig = getData((ms) => ms.data?.mentorConfig);
const mentorConfig: MentorConfig | undefined = getData(
(ms) => ms.data?.mentorConfig
);

const leftColumnAlign = "left";

Expand Down Expand Up @@ -62,7 +64,7 @@ function MentorStatus(props: {
</Typography>

{mentorInfo.currentStage.floor != 1000 &&
!mentorConfig.disableLevelProgressDisplay && (
!mentorConfig?.disableLevelProgressDisplay && (
<StageProgress
value={mentorInfo.value}
max={mentorInfo.currentStage.max || 0}
Expand Down
1 change: 1 addition & 0 deletions client/src/types-gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface MentorConfig {
disableKeywordsRecommendation: boolean;
disableThumbnailRecommendation: boolean;
disableLevelProgressDisplay: boolean;
completeSubjectsNotificationText: string;
}

export interface MentorGQL {
Expand Down

0 comments on commit a537195

Please sign in to comment.