Skip to content

Commit 5dec07a

Browse files
fix(calendar/dialog): sync subject options btwn pgs
1 parent 38bbe4e commit 5dec07a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

components/calendar/dialog/create-page.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,25 @@ export default function CreatePage({
9494
});
9595
}, [setEditing, editing.match.message]);
9696

97+
const subjectOptions = useMemo(() => {
98+
const subjects = new Set<string>();
99+
people.forEach((p) => {
100+
if (p.roles.includes('tutor'))
101+
p.tutoring.subjects.forEach((s) => subjects.add(s));
102+
if (p.roles.includes('mentor'))
103+
p.mentoring.subjects.forEach((s) => subjects.add(s));
104+
});
105+
return subjects.size ? [...subjects] : undefined;
106+
}, [people]);
107+
97108
// TODO: Add support to the `TimeSelect` and the `/api/users/availability` API
98109
// to query for the merged availability of multiple users (e.g. when all the
99110
// people in a match are available v.s. just one person).
100111
const timePersonId = useMemo(() => {
101112
const idx = people.findIndex(
102113
(p) => p.roles.includes('tutor') || p.roles.includes('mentor')
103114
);
104-
return idx < 0 ? '' : people[idx].id;
115+
return idx < 0 ? (people[0] || { id: '' }).id : people[idx].id;
105116
}, [people]);
106117

107118
return (
@@ -127,6 +138,7 @@ export default function CreatePage({
127138
onChange={onSubjectsChange}
128139
value={editing.match.subjects}
129140
className={styles.field}
141+
options={subjectOptions}
130142
renderToPortal
131143
outlined
132144
/>

components/calendar/dialog/edit-page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default function EditPage({
8686
if (p.roles.includes('mentor'))
8787
p.mentoring.subjects.forEach((s) => subjects.add(s));
8888
});
89-
return [...subjects];
89+
return subjects.size ? [...subjects] : undefined;
9090
}, [people]);
9191

9292
// TODO: Add support to the `TimeSelect` and the `/api/users/availability` API

0 commit comments

Comments
 (0)