diff --git a/src/containers/admin-dashBoard/Teams.tsx b/src/containers/admin-dashBoard/Teams.tsx index 235ba4152..9015dd8d9 100644 --- a/src/containers/admin-dashBoard/Teams.tsx +++ b/src/containers/admin-dashBoard/Teams.tsx @@ -34,6 +34,9 @@ export interface Team { name: string; cohort: Cohort; ttl: any; + manager: any; + phase: any; + program: any; } export const getAllTeam = gql` @@ -72,6 +75,15 @@ export const getAllTeam = gql` quality professional_Skills } + phase { + name + } + program { + name + } + manager { + email + } } getAllCohorts(orgToken: $orgToken) { @@ -96,6 +108,15 @@ export const getAllTeam = gql` role organizations } + getAllPrograms(orgToken: $orgToken) { + id + name + } + getAllPhases(orgToken: $orgToken) { + id + name + description + } } `; @@ -224,17 +245,16 @@ function AdminTeams() { }), }, ]; - - const teamData = getData?.getAllTeams.map(({ name, cohort, ttl }) => ({ - name, - cohortName: cohort?.name, - coordinator: cohort?.coordinator?.email - ? cohort?.coordinator?.email - : 'Not Assigned', - phase: cohort?.phase.name, - programName: cohort?.program?.name, - ttlEmail: ttl?.profile && ttl.profile.name ? ttl?.email : 'Not Assigned', - })); + const teamData = getData?.getAllTeams.map( + ({ name, cohort, ttl, phase, program, manager }) => ({ + name, + cohortName: cohort?.name, + coordinator: manager?.email ? manager?.email : cohort?.coordinator?.email, + phase: phase?.name ? phase?.name : cohort?.phase?.name, + programName: program?.name ? program?.name : cohort?.program?.name, + ttlEmail: ttl?.profile && ttl.profile.name ? ttl?.email : 'Not Assigned', + }), + ); return ( <> diff --git a/src/containers/admin-dashBoard/UpdateTeamModal.tsx b/src/containers/admin-dashBoard/UpdateTeamModal.tsx index 873ca2230..44dc242e1 100644 --- a/src/containers/admin-dashBoard/UpdateTeamModal.tsx +++ b/src/containers/admin-dashBoard/UpdateTeamModal.tsx @@ -14,6 +14,9 @@ export const UpdateTeam = gql` $cohort: String $TTL: String $orgToken: String + $manager: String + $phase: String + $program: String ) { updateTeam( id: $updateTeamId @@ -21,12 +24,14 @@ export const UpdateTeam = gql` name: $name cohort: $cohort TTL: $TTL + manager: $manager + phase: $phase + program: $program ) { name } } `; - export default function UpdateTeamModal({ data, updateTeamModal, @@ -37,6 +42,8 @@ export default function UpdateTeamModal({ data?: { getAllTeams: Team[]; getAllCohorts: Cohort[]; + getAllPrograms?: any[]; + getAllPhases?: any[]; getAllUsers: any; }; updateTeamModal: boolean; @@ -47,7 +54,6 @@ export default function UpdateTeamModal({ const { t } = useTranslation(); const { handleSubmit, - watch, formState: { errors }, reset, register, @@ -65,29 +71,29 @@ export default function UpdateTeamModal({ }, }); const orgToken = localStorage.getItem('orgToken'); - async function updateTeam(data: any) { const newData: any = { ...data }; - + // Process the select fields + newData.manager && (newData.manager = newData.manager.value); + newData.program && (newData.program = newData.program.value); + newData.phase && (newData.phase = newData.phase.value); newData.coordinatorEmail && (newData.coordinatorEmail = newData.coordinatorEmail.value); newData.programName && (newData.programName = newData.programName.value); - + // Clean up empty fields Object.keys(newData).forEach((field) => { if (!newData[field] || newData[field] === '') { delete newData[field]; } }); - newData.cohort && (newData.cohort = newData.cohort.value); newData.TTL && (newData.TTL = newData.TTL.value); newData.updateTeamId = currentTeam?.id; orgToken && (newData.orgToken = orgToken); - await updateTeamMutation({ variables: newData }); } - useEffect(() => { + // Set form values when the modal opens setValue('name', currentTeam?.name); setValue('TTL', { value: currentTeam?.ttl?.email, @@ -97,8 +103,29 @@ export default function UpdateTeamModal({ value: currentTeam?.cohort?.name, label: currentTeam?.cohort?.name || 'no cohort assigned', }); + setValue('manager', { + value: currentTeam?.manager?.email, + label: + currentTeam?.manager?.email || currentTeam?.cohort?.coordinator?.email, + }); + setValue('phase', { + value: currentTeam?.phase?.name + ? currentTeam?.phase?.name + : currentTeam?.cohort?.phase?.name, + label: currentTeam?.phase?.name + ? currentTeam?.phase?.name + : currentTeam?.cohort?.phase?.name || 'no phase assigned', + }); + // setValue('phase', currentTeam?.phase); + setValue('program', { + value: currentTeam?.program?.name + ? currentTeam?.program?.name + : currentTeam?.cohort?.program?.name, + label: currentTeam?.program?.name + ? currentTeam?.program?.name + : currentTeam?.cohort?.program?.name || 'no program assigned', + }); }, [currentTeam, updateTeamModal]); - return (