-
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.
- Loading branch information
Showing
23 changed files
with
1,124 additions
and
64 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
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
158 changes: 158 additions & 0 deletions
158
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,158 @@ | ||
import { CourseSummary } from '@klicker-uzh/graphql/dist/ops' | ||
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: CourseSummary | ||
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.numOfParticipations === 0 | ||
? t('manage.courseList.noParticipationsToDelete') | ||
: t('manage.courseList.deleteParticipations', { | ||
number: summary.numOfParticipations, | ||
}) | ||
} | ||
onClick={() => { | ||
setConfirmations((prev) => ({ | ||
...prev, | ||
deleteParticipations: true, | ||
})) | ||
}} | ||
confirmed={confirmations.deleteParticipations} | ||
notApplicable={summary.numOfParticipations === 0} | ||
data={{ cy: 'course-deletion-participations-confirm' }} | ||
/> | ||
<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} | ||
notApplicable={summary.numOfLiveQuizzes === 0} | ||
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} | ||
notApplicable={summary.numOfPracticeQuizzes === 0} | ||
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} | ||
notApplicable={summary.numOfMicroLearnings === 0} | ||
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} | ||
notApplicable={summary.numOfGroupActivities === 0} | ||
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} | ||
notApplicable={summary.numOfParticipantGroups === 0} | ||
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} | ||
notApplicable={summary.numOfLeaderboardEntries === 0} | ||
data={{ cy: 'course-deletion-leaderboard-entry-confirm' }} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default CourseDeletionConfirmations |
63 changes: 63 additions & 0 deletions
63
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,63 @@ | ||
import { | ||
faCheck, | ||
faExclamationCircle, | ||
faInfoCircle, | ||
} from '@fortawesome/free-solid-svg-icons' | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
import { Button } from '@uzh-bf/design-system' | ||
import { useTranslations } from 'next-intl' | ||
import { twMerge } from 'tailwind-merge' | ||
|
||
function CourseDeletionItem({ | ||
label, | ||
confirmed, | ||
notApplicable, | ||
onClick, | ||
data, | ||
}: { | ||
label: string | ||
confirmed: boolean | ||
notApplicable: 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 pl-2"> | ||
<div className="flex flex-row items-center gap-3.5"> | ||
<FontAwesomeIcon | ||
icon={notApplicable ? faInfoCircle : faExclamationCircle} | ||
className={twMerge( | ||
notApplicable | ||
? 'text-primary-80' | ||
: confirmed | ||
? 'text-gray-500' | ||
: 'text-red-600' | ||
)} | ||
/> | ||
<div | ||
className={twMerge( | ||
'mr-4', | ||
(notApplicable || confirmed) && 'text-gray-500' | ||
)} | ||
> | ||
{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.