-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure that state management works correctly again after structu…
…re changes
- Loading branch information
1 parent
5bb8d3c
commit f6279f5
Showing
5 changed files
with
217 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
apps/frontend-manage/src/components/courses/modals/CourseDeletionConfirmations.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { UserNotification } from '@uzh-bf/design-system' | ||
import { useTranslations } from 'next-intl' | ||
import { Dispatch, SetStateAction } from 'react' | ||
import CourseDeletionItem from './CourseDeletionItem' | ||
import { CourseDeletionConfirmationType } from './CourseDeletionModal' | ||
|
||
interface CourseDeletionConfirmationsProps { | ||
summary: { | ||
numOfLiveQuizzes: number | ||
numOfPracticeQuizzes: number | ||
numOfMicroLearnings: number | ||
numOfGroupActivities: number | ||
numOfParticipantGroups: number | ||
numOfLeaderboardEntries: number | ||
} | ||
confirmations: CourseDeletionConfirmationType | ||
setConfirmations: Dispatch<SetStateAction<CourseDeletionConfirmationType>> | ||
} | ||
|
||
function CourseDeletionConfirmations({ | ||
summary, | ||
confirmations, | ||
setConfirmations, | ||
}: CourseDeletionConfirmationsProps) { | ||
const t = useTranslations() | ||
|
||
return ( | ||
<div className="flex flex-col gap-2"> | ||
<UserNotification | ||
type="warning" | ||
message={t('manage.courseList.courseDeletionMessage')} | ||
className={{ root: 'mb-1 text-base' }} | ||
/> | ||
<CourseDeletionItem | ||
label={ | ||
summary.numOfLiveQuizzes === 0 | ||
? t('manage.courseList.noLiveQuizzesDisconnected') | ||
: t('manage.courseList.disconnectLiveQuizzes', { | ||
number: summary.numOfLiveQuizzes, | ||
}) | ||
} | ||
onClick={() => { | ||
setConfirmations((prev) => ({ | ||
...prev, | ||
disconnectLiveQuizzes: true, | ||
})) | ||
}} | ||
confirmed={confirmations.disconnectLiveQuizzes} | ||
data={{ cy: 'course-deletion-live-quiz-confirm' }} | ||
/> | ||
<CourseDeletionItem | ||
label={ | ||
summary.numOfPracticeQuizzes === 0 | ||
? t('manage.courseList.noPracticeQuizzesToDelete') | ||
: t('manage.courseList.deletePracticeQuizzes', { | ||
number: summary.numOfPracticeQuizzes, | ||
}) | ||
} | ||
onClick={() => { | ||
setConfirmations((prev) => ({ | ||
...prev, | ||
deletePracticeQuizzes: true, | ||
})) | ||
}} | ||
confirmed={confirmations.deletePracticeQuizzes} | ||
data={{ cy: 'course-deletion-practice-quiz-confirm' }} | ||
/> | ||
<CourseDeletionItem | ||
label={ | ||
summary.numOfMicroLearnings === 0 | ||
? t('manage.courseList.noMicroLearningsToDelete') | ||
: t('manage.courseList.deleteMicroLearnings', { | ||
number: summary.numOfMicroLearnings, | ||
}) | ||
} | ||
onClick={() => { | ||
setConfirmations((prev) => ({ | ||
...prev, | ||
deleteMicroLearnings: true, | ||
})) | ||
}} | ||
confirmed={confirmations.deleteMicroLearnings} | ||
data={{ cy: 'course-deletion-micro-learning-confirm' }} | ||
/> | ||
<CourseDeletionItem | ||
label={ | ||
summary.numOfGroupActivities === 0 | ||
? t('manage.courseList.noGroupActivitiesToDelete') | ||
: t('manage.courseList.deleteGroupActivities', { | ||
number: summary.numOfGroupActivities, | ||
}) | ||
} | ||
onClick={() => { | ||
setConfirmations((prev) => ({ | ||
...prev, | ||
deleteGroupActivities: true, | ||
})) | ||
}} | ||
confirmed={confirmations.deleteGroupActivities} | ||
data={{ cy: 'course-deletion-group-activity-confirm' }} | ||
/> | ||
<CourseDeletionItem | ||
label={ | ||
summary.numOfParticipantGroups === 0 | ||
? t('manage.courseList.noParticipantGroupsToDelete') | ||
: t('manage.courseList.deleteParticipantGroups', { | ||
number: summary.numOfParticipantGroups, | ||
}) | ||
} | ||
onClick={() => { | ||
setConfirmations((prev) => ({ | ||
...prev, | ||
deleteParticipantGroups: true, | ||
})) | ||
}} | ||
confirmed={confirmations.deleteParticipantGroups} | ||
data={{ cy: 'course-deletion-participant-group-confirm' }} | ||
/> | ||
<CourseDeletionItem | ||
label={ | ||
summary.numOfLeaderboardEntries === 0 | ||
? t('manage.courseList.noLeaderboardEntriesToDelete') | ||
: t('manage.courseList.deleteLeaderboardEntries', { | ||
number: summary.numOfLeaderboardEntries, | ||
}) | ||
} | ||
onClick={() => { | ||
setConfirmations((prev) => ({ | ||
...prev, | ||
deleteLeaderboardEntries: true, | ||
})) | ||
}} | ||
confirmed={confirmations.deleteLeaderboardEntries} | ||
data={{ cy: 'course-deletion-leaderboard-entry-confirm' }} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default CourseDeletionConfirmations |
40 changes: 40 additions & 0 deletions
40
apps/frontend-manage/src/components/courses/modals/CourseDeletionItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { faCheck, faExclamationCircle } from '@fortawesome/free-solid-svg-icons' | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
import { Button } from '@uzh-bf/design-system' | ||
import { useTranslations } from 'next-intl' | ||
|
||
function CourseDeletionItem({ | ||
label, | ||
confirmed, | ||
onClick, | ||
data, | ||
}: { | ||
label: string | ||
confirmed: boolean | ||
onClick: () => void | ||
data?: { cy?: string; test?: string } | ||
}) { | ||
const t = useTranslations() | ||
|
||
return ( | ||
<div className="flex h-10 flex-row items-center justify-between border-b pb-2"> | ||
<div className="flex flex-row items-center gap-4"> | ||
<FontAwesomeIcon icon={faExclamationCircle} className="text-red-600" /> | ||
<div className="mr-4">{label}</div> | ||
</div> | ||
{confirmed ? ( | ||
<FontAwesomeIcon icon={faCheck} className="text-green-700" /> | ||
) : ( | ||
<Button | ||
onClick={onClick} | ||
className={{ root: 'h-7 border-red-600' }} | ||
data={data} | ||
> | ||
{t('shared.generic.confirm')} | ||
</Button> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default CourseDeletionItem |
Oops, something went wrong.