Skip to content

Commit db1dc9e

Browse files
committed
fixed filtering
1 parent 392a75d commit db1dc9e

5 files changed

Lines changed: 411 additions & 110 deletions

File tree

‎src/app/accountManagement/page.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import InviteUserForm from "@/components/InviteUserForm";
88
import ConfirmationModal from "@/components/AccountManagement/ConfirmationModal";
99
import EditModal from "@/components/AccountManagement/EditModal";
1010
import { useApiClient } from "@/hooks/useApiClient";
11+
import { useFetch } from "@/hooks/useFetch";
1112
import { isStaff, formatUserType } from "@/lib/userUtils";
1213
import AccountDropdown from "@/components/AccountManagement/AccountDropdown";
1314
import AccountStatusTag from "@/components/tags/AccountStatusTag";
@@ -51,6 +52,9 @@ function getStatusLabel(user: AccountUserResponse) {
5152
export default function AccountManagementPage() {
5253
const tableRef = useRef<AdvancedBaseTableHandle<AccountRow>>(null);
5354
const { apiClient } = useApiClient();
55+
const { data: tags, refetch: refetchTags } = useFetch<string[]>(
56+
"/api/users/tags"
57+
);
5458

5559
const [isInviteModalOpen, setInviteModalOpen] = useState(false);
5660

@@ -134,6 +138,7 @@ export default function AccountManagementPage() {
134138

135139
tableRef.current?.upsertItem(nextUser);
136140
setSelectedUser(nextUser);
141+
refetchTags();
137142
} catch (error) {
138143
console.error("Error updating user:", error);
139144
}
@@ -198,7 +203,8 @@ export default function AccountManagementPage() {
198203
},
199204
{
200205
id: "tag",
201-
filterType: "string",
206+
filterType: "enum",
207+
filterOptions: tags ?? [],
202208
cell: (item) =>
203209
item.tag ? (
204210
<span className="px-3 py-1 bg-red-primary/70 text-white rounded-md text-sm">
@@ -334,6 +340,7 @@ This will restore the user's access to the system.`
334340
selectedUserId={
335341
selectedUser && !selectedUser.pending ? selectedUser.id : undefined
336342
}
343+
existingTags={tags ?? []}
337344
/>
338345
</>
339346
);

‎src/components/AccountManagement/EditModal.tsx‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { useState, useEffect } from "react";
22
import { UserType } from "@prisma/client";
33
import Select from "react-select/creatable";
44
import GeneralModal from "./GeneralModal";
5-
import { useFetch } from "@/hooks/useFetch";
65
import { useUser } from "@/components/context/UserContext";
76
import { isAdmin } from "@/lib/userUtils";
87

@@ -27,6 +26,7 @@ interface EditModalProps {
2726
cancelText?: string;
2827
isStaffAccount?: boolean;
2928
selectedUserId?: number;
29+
existingTags?: string[];
3030
}
3131

3232
export default function EditModal({
@@ -40,6 +40,7 @@ export default function EditModal({
4040
cancelText = "Cancel",
4141
isStaffAccount = true,
4242
selectedUserId,
43+
existingTags = [],
4344
}: EditModalProps) {
4445
const { user: currentUser } = useUser();
4546
const [formData, setFormData] = useState({
@@ -49,10 +50,6 @@ export default function EditModal({
4950
tag: "",
5051
});
5152

52-
const { data: existingTags } = useFetch<string[]>("/api/users/tags", {
53-
conditionalFetch: isOpen,
54-
});
55-
5653
useEffect(() => {
5754
if (initialData) {
5855
setFormData({
@@ -207,12 +204,10 @@ export default function EditModal({
207204
onChange={(selectedOption) =>
208205
handleInputChange("tag", selectedOption?.value || "")
209206
}
210-
options={
211-
existingTags?.map((tag) => ({
212-
value: tag,
213-
label: tag,
214-
})) || []
215-
}
207+
options={existingTags.map((tag) => ({
208+
value: tag,
209+
label: tag,
210+
}))}
216211
isClearable
217212
placeholder="Select or create a tag..."
218213
className="react-select-container"

‎src/components/baseTable/AdvancedBaseTable.tsx‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,17 @@ function AdvancedBaseTableInner<T extends object>(
128128

129129
let options: string[] | undefined;
130130
if (type === "enum") {
131-
const providedOptions = column.filterOptions ?? [];
132-
const collectedOptions = collectEnumOptions([
133-
...providedOptions,
134-
...(previousMeta?.options ?? []),
135-
...values,
136-
]);
137-
options =
138-
collectedOptions.length > 0 ? collectedOptions : providedOptions;
131+
// If filterOptions is explicitly provided, always use it
132+
if (column.filterOptions) {
133+
options = column.filterOptions;
134+
} else {
135+
// Otherwise, collect options from data
136+
const collectedOptions = collectEnumOptions([
137+
...(previousMeta?.options ?? []),
138+
...values,
139+
]);
140+
options = collectedOptions.length > 0 ? collectedOptions : undefined;
141+
}
139142
}
140143

141144
next.push({

0 commit comments

Comments
 (0)