Skip to content

Commit 6b3cae6

Browse files
Remove archived subjects from user management table and dropdown (#124)
Co-authored-by: Chinemerem <[email protected]>
1 parent 33e0699 commit 6b3cae6

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

src/components/dashboard/user_management/EditableSubscriptionsCell.tsx

+17-21
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,9 @@ const EditableSubscriptionsCell: React.FC<EditableSubscriptionsCellProps> = ({
7878

7979
// Get sorted subjects for dropdown display
8080
const sortedSubjects = useMemo(() => {
81-
return [...allSubjects].sort((a, b) => {
82-
// First sort by archived status (unarchived first)
83-
if (a.archived !== b.archived) {
84-
return a.archived ? 1 : -1;
85-
}
86-
// Then sort by ID
87-
return a.id - b.id;
88-
});
81+
return [...allSubjects]
82+
.filter((subject) => !subject.archived) // Filter out archived subjects
83+
.sort((a, b) => a.id - b.id); // Now we only need to sort by ID since all subjects are unarchived
8984
}, [allSubjects]);
9085

9186
// Define saveSubscriptions with useCallback so it can be used in dependency arrays
@@ -113,8 +108,14 @@ const EditableSubscriptionsCell: React.FC<EditableSubscriptionsCellProps> = ({
113108
// Initialize selected subjects from current mailing lists
114109
useEffect(() => {
115110
if (!isSaving) {
116-
setSelectedSubjectIds(mailingLists.map((list) => list.subjectId));
117-
setLocalMailingLists(mailingLists);
111+
setSelectedSubjectIds(
112+
mailingLists
113+
.filter((list) => !list.subject.archived)
114+
.map((list) => list.subjectId)
115+
);
116+
setLocalMailingLists(
117+
mailingLists.filter((list) => !list.subject.archived)
118+
);
118119
}
119120
}, [mailingLists, isSaving]);
120121

@@ -125,12 +126,12 @@ const EditableSubscriptionsCell: React.FC<EditableSubscriptionsCellProps> = ({
125126
.map((id) => {
126127
// Try to find existing mailing list first
127128
const existingList = mailingLists.find((list) => list.subjectId === id);
128-
if (existingList) return existingList;
129+
if (existingList && !existingList.subject.archived) return existingList;
129130

130131
// If not, create a new one based on the subject from our full subjects list
131132
const subject = subjectsById[id];
132133

133-
if (!subject) return null;
134+
if (!subject || subject.archived) return null;
134135

135136
return {
136137
subjectId: subject.id,
@@ -139,15 +140,10 @@ const EditableSubscriptionsCell: React.FC<EditableSubscriptionsCellProps> = ({
139140
})
140141
.filter(Boolean) as MailingList[];
141142

142-
// Sort the new mailing lists by archived status and ID
143-
const sortedMailingLists = [...newMailingListsUnsorted].sort((a, b) => {
144-
// First sort by archived status (unarchived first)
145-
if (a.subject.archived !== b.subject.archived) {
146-
return a.subject.archived ? 1 : -1;
147-
}
148-
// Then sort by ID
149-
return a.subjectId - b.subjectId;
150-
});
143+
// Sort the new mailing lists by ID
144+
const sortedMailingLists = [...newMailingListsUnsorted].sort(
145+
(a, b) => a.subjectId - b.subjectId
146+
);
151147

152148
setLocalMailingLists(sortedMailingLists);
153149
}, [selectedSubjectIds, mailingLists, subjectsById]);

0 commit comments

Comments
 (0)