From d1e7b7da0661f1895449cc6782b6912a252b8bef Mon Sep 17 00:00:00 2001 From: realmayus Date: Tue, 15 Oct 2024 12:05:59 +0200 Subject: [PATCH] update prospect list to use tailwind --- src/lang/de.json | 5 + src/modals/AddPupilModal.tsx | 15 ++- src/pages/single-course/ProspectList.tsx | 138 ++++++++++++----------- 3 files changed, 91 insertions(+), 67 deletions(-) diff --git a/src/lang/de.json b/src/lang/de.json index 19ecb0971..dd2f77b70 100644 --- a/src/lang/de.json +++ b/src/lang/de.json @@ -880,6 +880,11 @@ "cancel": "Abbrechen" } }, + "prospectList": { + "toast": "Schüler wurde dem Kurs hinzugefügt.", + "error": "Schüler:in konnte nicht hinzugefügt werden.", + "noProspects": "Keine Interessent:innen." + }, "joinPupilModal": { "header": "Schüler:innen nachrücken", "add": "Hinzufügen", diff --git a/src/modals/AddPupilModal.tsx b/src/modals/AddPupilModal.tsx index f7d4695cf..b11e6d476 100644 --- a/src/modals/AddPupilModal.tsx +++ b/src/modals/AddPupilModal.tsx @@ -13,6 +13,7 @@ interface AddPupilModalProps extends BaseModalProps { subcourseId: number; pupil?: PupilOnWaitinglist; onPupilAdded: () => Promise; + type: 'waitinglist' | 'prospectlist'; } // type JoinPupilModalProps = { // pupil: (SparseParticipant & { schooltype: string | undefined; gradeAsInt: number | undefined }) | undefined; @@ -23,18 +24,24 @@ const ADD_PUPIL_FROM_WAITING_LIST_MUTATION = gql(`mutation JoinFromWaitinglist($ subcourseJoinFromWaitinglist(subcourseId: $subcourseId, pupilId: $pupilId) }`); -const AddPupilModal = ({ isOpen, onOpenChange, subcourseId, pupil, onPupilAdded }: AddPupilModalProps) => { +const ADD_PUPIL_FROM_PROSPECT_LIST_MUTATION = gql(`mutation JoinFromProspectList($subcourseId: Float!, $pupilId: Float!) { + subcourseJoinFromProspects(subcourseId: $subcourseId, pupilId: $pupilId) +}`); + +const AddPupilModal = ({ isOpen, onOpenChange, subcourseId, pupil, onPupilAdded, type }: AddPupilModalProps) => { const { t } = useTranslation(); - const [addPupil, { loading: isAdding }] = useMutation(ADD_PUPIL_FROM_WAITING_LIST_MUTATION); + const [addPupil, { loading: isAdding }] = useMutation( + type === 'waitinglist' ? ADD_PUPIL_FROM_WAITING_LIST_MUTATION : ADD_PUPIL_FROM_PROSPECT_LIST_MUTATION + ); const handleOnAddPupil = async () => { if (!pupil) return; try { await addPupil({ variables: { subcourseId, pupilId: pupil.id } }); - toast.success(t('single.waitinglist.toast')); + toast.success(t(type === 'waitinglist' ? 'single.waitinglist.toast' : 'single.prospectList.toast')); if (onPupilAdded) await onPupilAdded(); } catch (error) { - toast.error(t('single.waitinglist.error')); + toast.error(t(type === 'waitinglist' ? 'single.waitinglist.error' : 'single.prospectList.error')); } finally { onOpenChange(false); } diff --git a/src/pages/single-course/ProspectList.tsx b/src/pages/single-course/ProspectList.tsx index e12f20f32..7fc9d5c46 100644 --- a/src/pages/single-course/ProspectList.tsx +++ b/src/pages/single-course/ProspectList.tsx @@ -1,83 +1,95 @@ -import { Box, Button, Column, Heading, Modal, Row, Spacer, useBreakpointValue, useTheme, useToast } from 'native-base'; -import AddCircleIcon from '../../assets/icons/ic_add_circle.svg'; -import AddPupilModal from '../../modals/AddPupilModal'; +import { ApolloQueryResult } from '@apollo/client'; import { useCallback, useState } from 'react'; -import { SparseParticipant } from '../../gql/graphql'; -import { ApolloQueryResult, useMutation } from '@apollo/client'; -import { gql } from '../../gql'; +import { LFPupilsOnWaitinglist, PupilOnWaitinglist, SparseParticipant } from '@/types/lernfair/Course'; import { useTranslation } from 'react-i18next'; +import AddPupilModal from '@/modals/AddPupilModal'; +import IncreaseMaxParticipantsModal from '@/modals/IncreaseMaxParticipantsModal'; +import ParticipantRow from '../subcourse/ParticipantRow'; +import { Button } from '@/components/Button'; +import { Alert } from '@/components/Alert'; +import { IconCircleCheckFilled } from '@tabler/icons-react'; type ProspectListProps = { subcourseId: number; prospects: SparseParticipant[]; + maxParticipants: number; refetch: () => Promise>; }; -const ProspectList: React.FC = ({ prospects, subcourseId, refetch }) => { - const { space } = useTheme(); - const { t } = useTranslation(); - const toast = useToast(); - const [isFetching, setFetching] = useState(false); - const isMobile = useBreakpointValue({ - base: true, - lg: false, - }); +const ProspectList: React.FC = ({ subcourseId, prospects, maxParticipants, refetch }) => { const [isJoinPupilModalOpen, setIsJoinPupilModalOpen] = useState(false); - const [pupilToAdd, setPupilToAdd] = useState(); + const [isIncreaseMaxParticipantsModalOpen, setIsIncreaseMaxParticipantsModalOpen] = useState(false); + const [pupilToAdd, setPupilToAdd] = useState(); - const [addProspect] = useMutation( - gql(`mutation JoinProspect($subcourseId: Float!, $pupilId: Float!) { - subcourseJoinFromProspects(subcourseId: $subcourseId, pupilId: $pupilId) - }`) - ); + const { t } = useTranslation(); - const handleOpenModal = (prospect: SparseParticipant) => { + const handleOpenModal = (pupilOnWaitinglist: PupilOnWaitinglist) => { setIsJoinPupilModalOpen(true); - setPupilToAdd(prospect); + setPupilToAdd(pupilOnWaitinglist); }; - const handleAddPupil = useCallback( - async (pupilId: number) => { - try { - setFetching(true); - await addProspect({ variables: { subcourseId: subcourseId, pupilId: pupilId } }); - setIsJoinPupilModalOpen(false); - toast.show({ description: t('single.waitinglist.toast'), placement: 'top' }); - await refetch(); - } catch (error) { - toast.show({ description: t('single.waitinglist.error'), placement: 'top' }); - } finally { - setFetching(false); - } - }, - [addProspect, refetch, subcourseId] - ); + const handleOnFinish = useCallback(async () => { + refetch(); + }, [refetch]); + return ( <> - {prospects?.map((pupil) => { - return ( - <> - - - - - {pupil.firstname} {pupil.lastname} - - - - - - - - setIsJoinPupilModalOpen(false)} w="full"> - - - - - ); - })} +
+
+ {pupilsOnWaitinglist && pupilsOnWaitinglist?.length > 0 ? ( + + ) : ( + }> + {t('single.waitinglist.noPupilsOnWaitinglist')} + + )} +
+
+ {prospects.map((pupil) => { + return ( + + handleOpenModal({ + id: participant.id, + firstname: participant.firstname, + lastname: participant.lastname!, + gradeAsInt: participant.gradeAsInt, + grade: participant.grade, + schooltype: participant.schooltype!, + }) + } + /> + ); + })} +
+
+ + ); };