Skip to content

Commit 8053291

Browse files
janet-barbieTuyisenge2
authored andcommitted
fixing update team info
1 parent 9d93b8f commit 8053291

File tree

2 files changed

+175
-61
lines changed

2 files changed

+175
-61
lines changed

src/containers/admin-dashBoard/Teams.tsx

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export interface Team {
3434
name: string;
3535
cohort: Cohort;
3636
ttl: any;
37+
manager: any;
38+
phase: any;
39+
program: any;
3740
}
3841

3942
export const getAllTeam = gql`
@@ -72,6 +75,13 @@ export const getAllTeam = gql`
7275
quality
7376
professional_Skills
7477
}
78+
79+
phase {
80+
name
81+
}
82+
program {
83+
name
84+
}
7585
}
7686
7787
getAllCohorts(orgToken: $orgToken) {
@@ -96,6 +106,15 @@ export const getAllTeam = gql`
96106
role
97107
organizations
98108
}
109+
getAllPrograms(orgToken: $orgToken) {
110+
id
111+
name
112+
}
113+
getAllPhases(orgToken: $orgToken) {
114+
id
115+
name
116+
description
117+
}
99118
}
100119
`;
101120

@@ -224,17 +243,18 @@ function AdminTeams() {
224243
}),
225244
},
226245
];
227-
228-
const teamData = getData?.getAllTeams.map(({ name, cohort, ttl }) => ({
229-
name,
230-
cohortName: cohort?.name,
231-
coordinator: cohort?.coordinator?.email
232-
? cohort?.coordinator?.email
233-
: 'Not Assigned',
234-
phase: cohort?.phase.name,
235-
programName: cohort?.program?.name,
236-
ttlEmail: ttl?.profile && ttl.profile.name ? ttl?.email : 'Not Assigned',
237-
}));
246+
const teamData = getData?.getAllTeams.map(
247+
({ name, cohort, ttl, phase, program }) => ({
248+
name,
249+
cohortName: cohort?.name,
250+
coordinator: cohort?.coordinator?.email
251+
? cohort?.coordinator?.email
252+
: 'Not Assigned',
253+
phase: phase?.name ? phase?.name : cohort?.phase?.name,
254+
programName: program?.name ? program?.name : cohort?.program?.name,
255+
ttlEmail: ttl?.profile && ttl.profile.name ? ttl?.email : 'Not Assigned',
256+
}),
257+
);
238258

239259
return (
240260
<>

src/containers/admin-dashBoard/UpdateTeamModal.tsx

Lines changed: 144 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,24 @@ export const UpdateTeam = gql`
1414
$cohort: String
1515
$TTL: String
1616
$orgToken: String
17+
$manager: String
18+
$phase: String
19+
$program: String
1720
) {
1821
updateTeam(
1922
id: $updateTeamId
2023
orgToken: $orgToken
2124
name: $name
2225
cohort: $cohort
2326
TTL: $TTL
27+
manager: $manager
28+
phase: $phase
29+
program: $program
2430
) {
2531
name
2632
}
2733
}
2834
`;
29-
3035
export default function UpdateTeamModal({
3136
data,
3237
updateTeamModal,
@@ -37,6 +42,8 @@ export default function UpdateTeamModal({
3742
data?: {
3843
getAllTeams: Team[];
3944
getAllCohorts: Cohort[];
45+
getAllPrograms?: any[];
46+
getAllPhases?: any[];
4047
getAllUsers: any;
4148
};
4249
updateTeamModal: boolean;
@@ -47,7 +54,6 @@ export default function UpdateTeamModal({
4754
const { t } = useTranslation();
4855
const {
4956
handleSubmit,
50-
watch,
5157
formState: { errors },
5258
reset,
5359
register,
@@ -65,29 +71,29 @@ export default function UpdateTeamModal({
6571
},
6672
});
6773
const orgToken = localStorage.getItem('orgToken');
68-
6974
async function updateTeam(data: any) {
7075
const newData: any = { ...data };
71-
76+
// Process the select fields
77+
newData.manager && (newData.manager = newData.manager.value);
78+
newData.program && (newData.program = newData.program.value);
79+
newData.phase && (newData.phase = newData.phase.value);
7280
newData.coordinatorEmail &&
7381
(newData.coordinatorEmail = newData.coordinatorEmail.value);
7482
newData.programName && (newData.programName = newData.programName.value);
75-
83+
// Clean up empty fields
7684
Object.keys(newData).forEach((field) => {
7785
if (!newData[field] || newData[field] === '') {
7886
delete newData[field];
7987
}
8088
});
81-
8289
newData.cohort && (newData.cohort = newData.cohort.value);
8390
newData.TTL && (newData.TTL = newData.TTL.value);
8491
newData.updateTeamId = currentTeam?.id;
8592
orgToken && (newData.orgToken = orgToken);
86-
8793
await updateTeamMutation({ variables: newData });
8894
}
89-
9095
useEffect(() => {
96+
// Set form values when the modal opens
9197
setValue('name', currentTeam?.name);
9298
setValue('TTL', {
9399
value: currentTeam?.ttl?.email,
@@ -97,8 +103,28 @@ export default function UpdateTeamModal({
97103
value: currentTeam?.cohort?.name,
98104
label: currentTeam?.cohort?.name || 'no cohort assigned',
99105
});
106+
setValue('manager', {
107+
value: currentTeam?.manager?.email,
108+
label: currentTeam?.manager?.email || 'no manager assigned',
109+
});
110+
setValue('phase', {
111+
value: currentTeam?.phase?.name
112+
? currentTeam?.phase?.name
113+
: currentTeam?.cohort?.phase?.name,
114+
label: currentTeam?.phase?.name
115+
? currentTeam?.phase?.name
116+
: currentTeam?.cohort?.phase?.name || 'no phase assigned',
117+
});
118+
// setValue('phase', currentTeam?.phase);
119+
setValue('program', {
120+
value: currentTeam?.program?.name
121+
? currentTeam?.program?.name
122+
: currentTeam?.cohort?.program?.name,
123+
label: currentTeam?.program?.name
124+
? currentTeam?.program?.name
125+
: currentTeam?.cohort?.program?.name || 'no program assigned',
126+
});
100127
}, [currentTeam, updateTeamModal]);
101-
102128
return (
103129
<div
104130
className={`h-screen w-screen bg-black fixed top-0 left-0 bg-opacity-30 backdrop-blur-sm flex items-center justify-center z-20 overflow-auto p-4 ${
@@ -111,54 +137,50 @@ export default function UpdateTeamModal({
111137
<h3 className="w-11/12 text-sm font-bold text-center uppercase dark:text-white">
112138
{t('Update Team')}
113139
</h3>
114-
<hr className="w-full my-3 border-b bg-primary" />
140+
<hr className="w-full my-3 border-b bg-primary" />
115141
</div>
116142
<div className="card-body">
117143
<form className="px-8 py-3 ">
118-
<div className="my-5 input h-9 ">
119-
<div className="flex items-center w-full h-full rounded-md grouped-input">
120-
<input
121-
type="text"
122-
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"
123-
placeholder={t('name')}
124-
{...register('name')}
125-
/>
126-
</div>
144+
{/* Team Name */}
145+
<div className="my-5 input h-9">
146+
<input
147+
type="text"
148+
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"
149+
placeholder={t('name')}
150+
{...register('name')}
151+
/>
127152
{errors?.name && (
128153
<p className="font-thin text-[12px] text-red-300">
129154
{errors?.name?.message?.toString()}
130155
</p>
131156
)}
132157
</div>
158+
{/* TTL Email */}
133159
<div className="my-5 input h-9">
134-
<div className="flex items-center w-full h-full rounded-md grouped-input">
135-
<ControlledSelect
136-
placeholder={t('email')}
137-
register={{
138-
control,
139-
name: 'TTL',
140-
rules: {
141-
required: `${t('The ttl email is required')}`,
142-
},
143-
}}
144-
options={
145-
data?.getAllUsers
146-
?.filter((user: any) => user.role === 'ttl')
147-
?.map((user: any) => ({
148-
value: user.email,
149-
label: user.email,
150-
})) ?? []
151-
}
152-
/>
153-
</div>
154-
{errors?.ttlEmail && (
160+
<ControlledSelect
161+
placeholder={t('email')}
162+
register={{
163+
control,
164+
name: 'TTL',
165+
rules: { required: `${t('The ttl email is required')}` },
166+
}}
167+
options={
168+
data?.getAllUsers
169+
?.filter((user: any) => user.role === 'ttl')
170+
?.map((user: any) => ({
171+
value: user.email,
172+
label: user.email,
173+
})) ?? []
174+
}
175+
/>
176+
{errors?.TTL && (
155177
<p className="font-thin text-[12px] text-red-300">
156-
{errors?.ttlEmail?.message?.toString()}
178+
{errors?.TTL?.message?.toString()}
157179
</p>
158180
)}
159181
</div>
160-
161-
<div className="my-5 input h-9 ">
182+
{/* Cohort */}
183+
<div className="my-5 input h-9">
162184
<ControlledSelect
163185
placeholder={t('Choose a Cohort')}
164186
register={{
@@ -171,13 +193,86 @@ export default function UpdateTeamModal({
171193
label: name,
172194
}))}
173195
/>
174-
{errors?.programName && (
196+
{errors?.cohort && (
175197
<p className="font-thin text-[12px] text-red-300">
176-
{errors?.programName?.message?.toString()}
198+
{errors?.cohort?.message?.toString()}
199+
</p>
200+
)}
201+
</div>
202+
{/* Manager */}
203+
<div className="my-5 input h-9">
204+
<ControlledSelect
205+
placeholder={t('Manager')}
206+
register={{
207+
control,
208+
name: 'manager',
209+
rules: { required: `${t('Manager is required')}` },
210+
}}
211+
options={
212+
data?.getAllUsers
213+
?.filter((user: any) => user.role === 'manager')
214+
?.map((user: any) => ({
215+
value: user.email,
216+
label: user.email,
217+
})) ?? []
218+
}
219+
/>
220+
{errors?.manager && (
221+
<p className="font-thin text-[12px] text-red-300">
222+
{errors?.manager?.message?.toString()}
223+
</p>
224+
)}
225+
</div>
226+
{/* Phase */}
227+
{/* <div className="my-5 input h-9">
228+
<input
229+
type="text"
230+
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"
231+
placeholder={t('Phase')}
232+
{...register('phase', {
233+
required: `${t('Phase is required')}`,
234+
})}
235+
/>
236+
{errors?.phase && (
237+
<p className="font-thin text-[12px] text-red-300">
238+
{errors?.phase?.message?.toString()}
239+
</p>
240+
)}
241+
</div> */}
242+
<div className="my-5 input h-9">
243+
<ControlledSelect
244+
placeholder={t('Phases')}
245+
register={{
246+
control,
247+
name: 'phase', // Ensure this matches your backend mutation variable
248+
rules: { required: `${t('Phase is required')}` },
249+
}}
250+
options={data?.getAllPhases?.map(({ id, name }) => ({
251+
value: id,
252+
label: name,
253+
}))}
254+
/>
255+
</div>
256+
{/* Program */}
257+
<div className="my-5 input h-9">
258+
<ControlledSelect
259+
placeholder={t('Program')}
260+
register={{
261+
control,
262+
name: 'program',
263+
rules: { required: `${t('Program is required')}` },
264+
}}
265+
options={data?.getAllPrograms?.map(({ name }) => ({
266+
value: name,
267+
label: name,
268+
}))}
269+
/>
270+
{errors?.program && (
271+
<p className="font-thin text-[12px] text-red-300">
272+
{errors?.program?.message?.toString()}
177273
</p>
178274
)}
179275
</div>
180-
181276
<div className="flex justify-between w-full">
182277
<Button
183278
variant="info"
@@ -190,18 +285,17 @@ export default function UpdateTeamModal({
190285
}}
191286
disabled={loading}
192287
>
193-
{' '}
194288
{t('Cancel')}
195289
</Button>
196290
<Button
197291
variant="primary"
198292
size="sm"
199-
style="w-[30%] md:w-1/4 text-sm font-sans p-0"
293+
style="w-[30%] md:w-1/4 text-sm font-sans"
294+
data-testid="updateTeam"
200295
onClick={handleSubmit(updateTeam)}
201296
loading={loading}
202-
data-testid="confirmUpdateBtn"
297+
disabled={loading}
203298
>
204-
{' '}
205299
{t('Save')}
206300
</Button>
207301
</div>

0 commit comments

Comments
 (0)