Skip to content

Commit

Permalink
fixing update team info
Browse files Browse the repository at this point in the history
  • Loading branch information
janet-barbie committed Sep 26, 2024
1 parent 9d93b8f commit 9573452
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 40 deletions.
12 changes: 12 additions & 0 deletions src/containers/admin-dashBoard/Teams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export interface Team {
name: string;
cohort: Cohort;
ttl: any;
manager:any;
phase:any;
program:any;
}

export const getAllTeam = gql`
Expand Down Expand Up @@ -96,6 +99,15 @@ export const getAllTeam = gql`
role
organizations
}
getAllPrograms(orgToken:$orgToken){
id
name
}
getAllPhases(orgToken:$orgToken){
id
name
description
}
}
`;

Expand Down
179 changes: 139 additions & 40 deletions src/containers/admin-dashBoard/UpdateTeamModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ export const UpdateTeam = gql`
$cohort: String
$TTL: String
$orgToken: String
$manager: String
$phase: String
$program: String
) {
updateTeam(
id: $updateTeamId
orgToken: $orgToken
name: $name
cohort: $cohort
TTL: $TTL
manager: $manager
phase: $phase
program: $program
) {
name
}
Expand All @@ -37,6 +43,8 @@ export default function UpdateTeamModal({
data?: {
getAllTeams: Team[];
getAllCohorts: Cohort[];
getAllPrograms?: any[];
getAllPhases?: any[];
getAllUsers: any;
};
updateTeamModal: boolean;
Expand All @@ -47,7 +55,6 @@ export default function UpdateTeamModal({
const { t } = useTranslation();
const {
handleSubmit,
watch,
formState: { errors },
reset,
register,
Expand All @@ -69,10 +76,16 @@ export default function UpdateTeamModal({
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];
Expand All @@ -88,6 +101,7 @@ export default function UpdateTeamModal({
}

useEffect(() => {
// Set form values when the modal opens
setValue('name', currentTeam?.name);
setValue('TTL', {
value: currentTeam?.ttl?.email,
Expand All @@ -97,6 +111,19 @@ 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 || 'no manager assigned',
});
// setValue('phase', {
// value: currentTeam?.phase?.name,
// label: currentTeam?.phase?.name || 'no phase assigned',
// });
setValue('phase', currentTeam?.phase)
setValue('program', {
value: currentTeam?.program?.name,
label: currentTeam?.program?.name || 'no program assigned',
});
}, [currentTeam, updateTeamModal]);

return (
Expand All @@ -111,54 +138,52 @@ export default function UpdateTeamModal({
<h3 className="w-11/12 text-sm font-bold text-center uppercase dark:text-white">
{t('Update Team')}
</h3>
<hr className="w-full my-3 border-b bg-primary" />
<hr className="w-full my-3 border-b bg-primary" />
</div>
<div className="card-body">
<form className="px-8 py-3 ">
<div className="my-5 input h-9 ">
<div className="flex items-center w-full h-full rounded-md grouped-input">
<input
type="text"
className="w-full px-5 py-2 font-sans text-xs border rounded outline-none border-primary dark:bg-dark-frame-bg dark:text-white"
placeholder={t('name')}
{...register('name')}
/>
</div>
{/* Team Name */}
<div className="my-5 input h-9">
<input
type="text"
className="w-full px-5 py-2 font-sans text-xs border rounded outline-none border-primary dark:bg-dark-frame-bg dark:text-white"
placeholder={t('name')}
{...register('name')}
/>
{errors?.name && (
<p className="font-thin text-[12px] text-red-300">
{errors?.name?.message?.toString()}
</p>
)}
</div>

{/* TTL Email */}
<div className="my-5 input h-9">
<div className="flex items-center w-full h-full rounded-md grouped-input">
<ControlledSelect
placeholder={t('email')}
register={{
control,
name: 'TTL',
rules: {
required: `${t('The ttl email is required')}`,
},
}}
options={
data?.getAllUsers
?.filter((user: any) => user.role === 'ttl')
?.map((user: any) => ({
value: user.email,
label: user.email,
})) ?? []
}
/>
</div>
{errors?.ttlEmail && (
<ControlledSelect
placeholder={t('email')}
register={{
control,
name: 'TTL',
rules: { required: `${t('The ttl email is required')}` },
}}
options={
data?.getAllUsers
?.filter((user: any) => user.role === 'ttl')
?.map((user: any) => ({
value: user.email,
label: user.email,
})) ?? []
}
/>
{errors?.TTL && (
<p className="font-thin text-[12px] text-red-300">
{errors?.ttlEmail?.message?.toString()}
{errors?.TTL?.message?.toString()}
</p>
)}
</div>

<div className="my-5 input h-9 ">
{/* Cohort */}
<div className="my-5 input h-9">
<ControlledSelect
placeholder={t('Choose a Cohort')}
register={{
Expand All @@ -171,9 +196,84 @@ export default function UpdateTeamModal({
label: name,
}))}
/>
{errors?.programName && (
{errors?.cohort && (
<p className="font-thin text-[12px] text-red-300">
{errors?.cohort?.message?.toString()}
</p>
)}
</div>

{/* Manager */}
<div className="my-5 input h-9">
<ControlledSelect
placeholder={t('Manager')}
register={{
control,
name: 'manager',
rules: { required: `${t('Manager is required')}` },
}}
options={
data?.getAllUsers
?.filter((user: any) => user.role === 'manager')
?.map((user: any) => ({
value: user.email,
label: user.email,
})) ?? []
}
/>
{errors?.manager && (
<p className="font-thin text-[12px] text-red-300">
{errors?.manager?.message?.toString()}
</p>
)}
</div>

{/* Phase */}
<div className="my-5 input h-9">
<input
type="text"
className="w-full px-5 py-2 font-sans text-xs border rounded outline-none border-primary dark:bg-dark-frame-bg dark:text-white"
placeholder={t('Phase')}
{...register('phase', { required: `${t('Phase is required')}` })}
/>
{errors?.phase && (
<p className="font-thin text-[12px] text-red-300">
{errors?.phase?.message?.toString()}
</p>
)}
</div>
{/* <div className="my-5 input h-9">
<ControlledSelect
placeholder={t('Phases')}
register={{
control,
name: 'phase', // Ensure this matches your backend mutation variable
rules: { required: `${t('Phase is required')}` },
}}
options={data?.getAllPhases?.map(({ id,name }) => ({
value: id,
label: name,
}))}
/>
</div> */}

{/* Program */}
<div className="my-5 input h-9">
<ControlledSelect
placeholder={t('Program')}
register={{
control,
name: 'program',
rules: { required: `${t('Program is required')}` },
}}
options={data?.getAllPrograms?.map(({ name }) => ({
value: name,
label: name,
}))}
/>
{errors?.program && (
<p className="font-thin text-[12px] text-red-300">
{errors?.programName?.message?.toString()}
{errors?.program?.message?.toString()}
</p>
)}
</div>
Expand All @@ -190,18 +290,17 @@ export default function UpdateTeamModal({
}}
disabled={loading}
>
{' '}
{t('Cancel')}
</Button>
<Button
variant="primary"
size="sm"
style="w-[30%] md:w-1/4 text-sm font-sans p-0"
style="w-[30%] md:w-1/4 text-sm font-sans"
data-testid="updateTeam"
onClick={handleSubmit(updateTeam)}
loading={loading}
data-testid="confirmUpdateBtn"
disabled={loading}
>
{' '}
{t('Save')}
</Button>
</div>
Expand Down

0 comments on commit 9573452

Please sign in to comment.