Skip to content

Commit e6119cb

Browse files
committed
fix: disable export button
1 parent 6336fc9 commit e6119cb

File tree

9 files changed

+581
-390
lines changed

9 files changed

+581
-390
lines changed

client/src/components/admin/ManageAccounts.tsx

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ import {
3636
} from "@tanstack/react-table";
3737
import { MdFileUpload, MdOutlineManageSearch } from "react-icons/md";
3838

39-
import { useBackendContext } from "../../contexts/hooks/useBackendContext";
4039
import { useAuthContext } from "../../contexts/hooks/useAuthContext";
40+
import { useBackendContext } from "../../contexts/hooks/useBackendContext";
4141
import { downloadCSV } from "../../utils/downloadCSV.ts";
4242
import { HoverCheckbox } from "../hoverCheckbox/hoverCheckbox.tsx";
4343
import EditClient from "../userSettings/EditClient";
@@ -79,7 +79,7 @@ export const ManageAccounts = () => {
7979
location: "",
8080
phoneNumber: "",
8181
email: "",
82-
notes: ""
82+
notes: "",
8383
});
8484

8585
const [sorting, setSorting] = useState<SortingState>([]);
@@ -91,7 +91,9 @@ export const ManageAccounts = () => {
9191
} = useDisclosure();
9292
const [editDrawerOpened, setEditDrawerOpened] = useState(false);
9393
const [selectedRowIds, setSelectedRowIds] = useState<number[]>([]);
94-
const [checkboxMode, setCheckboxMode] = useState<'hidden' | 'visible-unchecked' | 'visible-checked'>('hidden');
94+
const [checkboxMode, setCheckboxMode] = useState<
95+
"hidden" | "visible-unchecked" | "visible-checked"
96+
>("hidden");
9597
const toast = useToast();
9698

9799
const buttonStyle = {
@@ -117,20 +119,19 @@ export const ManageAccounts = () => {
117119
}
118120
};
119121

120-
121122
const handleSelectAllCheckboxClick = () => {
122-
if (checkboxMode === 'hidden') {
123+
if (checkboxMode === "hidden") {
123124
// State 1 -> State 2: Show checkboxes and select all
124-
setCheckboxMode('visible-checked');
125+
setCheckboxMode("visible-checked");
125126
const allIds = persons.map((person) => person.id);
126127
setSelectedRowIds(allIds);
127-
} else if (checkboxMode === 'visible-checked') {
128+
} else if (checkboxMode === "visible-checked") {
128129
// State 2 -> State 3: Keep checkboxes visible but uncheck all
129-
setCheckboxMode('visible-unchecked');
130+
setCheckboxMode("visible-unchecked");
130131
setSelectedRowIds([]);
131132
} else {
132133
// State 3 -> State 1: Hide checkboxes
133-
setCheckboxMode('hidden');
134+
setCheckboxMode("hidden");
134135
setSelectedRowIds([]);
135136
}
136137
};
@@ -141,11 +142,10 @@ export const ManageAccounts = () => {
141142

142143
const handleDelete = async () => {
143144
try {
144-
145145
selectedRowIds.map(async (row_id) => {
146146
const caseManager = await backend.delete(`/caseManagers/${row_id}`);
147147
await backend.delete(`/users/email/${caseManager.data[0].email}`);
148-
})
148+
});
149149
setPersons(
150150
persons.filter((client) => !selectedRowIds.includes(client.id))
151151
);
@@ -196,8 +196,8 @@ export const ManageAccounts = () => {
196196
return (
197197
<Box textAlign="center">
198198
<Checkbox
199-
isChecked={checkboxMode === 'visible-checked'}
200-
isIndeterminate={checkboxMode === 'visible-unchecked'}
199+
isChecked={checkboxMode === "visible-checked"}
200+
isIndeterminate={checkboxMode === "visible-unchecked"}
201201
onChange={handleSelectAllCheckboxClick}
202202
/>
203203
</Box>
@@ -233,19 +233,27 @@ export const ManageAccounts = () => {
233233
cell: ({ getValue }) => {
234234
const notes = getValue() as string;
235235
const maxLength = 20; // Maximum characters to show before truncation
236-
236+
237237
if (!notes || notes.length === 0) {
238-
return <Text color="gray.400" fontStyle="italic">No notes</Text>;
238+
return (
239+
<Text
240+
color="gray.400"
241+
fontStyle="italic"
242+
>
243+
No notes
244+
</Text>
245+
);
239246
}
240-
241-
const truncatedNotes = notes.length > maxLength
242-
? `${notes.substring(0, maxLength)}...`
243-
: notes;
244-
247+
248+
const truncatedNotes =
249+
notes.length > maxLength
250+
? `${notes.substring(0, maxLength)}...`
251+
: notes;
252+
245253
return (
246-
<Tooltip
247-
label={notes}
248-
placement="top"
254+
<Tooltip
255+
label={notes}
256+
placement="top"
249257
hasArrow
250258
maxW="400px"
251259
whiteSpace="pre-wrap"
@@ -342,7 +350,7 @@ export const ManageAccounts = () => {
342350
setView("admin");
343351
setEditDrawerOpened(false);
344352
setSelectedRowIds([]);
345-
setCheckboxMode('hidden');
353+
setCheckboxMode("hidden");
346354
}}
347355
>
348356
Admins
@@ -352,7 +360,7 @@ export const ManageAccounts = () => {
352360
setView("cms");
353361
setEditDrawerOpened(false);
354362
setSelectedRowIds([]);
355-
setCheckboxMode('hidden');
363+
setCheckboxMode("hidden");
356364
}}
357365
>
358366
Case Managers
@@ -362,7 +370,7 @@ export const ManageAccounts = () => {
362370
setView("clients");
363371
setEditDrawerOpened(false);
364372
setSelectedRowIds([]);
365-
setCheckboxMode('hidden');
373+
setCheckboxMode("hidden");
366374
}}
367375
>
368376
Clients
@@ -373,8 +381,8 @@ export const ManageAccounts = () => {
373381
<Spacer />
374382
{view !== "clients" && (
375383
<>
376-
<Button
377-
onClick={deleteOnOpen}
384+
<Button
385+
onClick={deleteOnOpen}
378386
disabled={selectedRowIds.length === 0}
379387
colorScheme={selectedRowIds.length === 0 ? "gray" : "red"}
380388
opacity={selectedRowIds.length === 0 ? 0.5 : 1}
@@ -420,6 +428,7 @@ export const ManageAccounts = () => {
420428
{...buttonStyle}
421429
leftIcon={<MdFileUpload />}
422430
onClick={() => onPressCSVButton()}
431+
isDisabled={selectedRowIds.length === 0}
423432
>
424433
Export
425434
</Button>
@@ -482,15 +491,15 @@ export const ManageAccounts = () => {
482491
}}
483492
>
484493
{cell.column.id === "rowNumber" ? (
485-
<HoverCheckbox
486-
id={row.original.id}
487-
isSelected={selectedRowIds.includes(
488-
row.original.id
489-
)}
490-
onSelectionChange={handleRowSelect}
491-
index={index}
492-
alwaysVisible={checkboxMode !== 'hidden'}
493-
/>
494+
<HoverCheckbox
495+
id={row.original.id}
496+
isSelected={selectedRowIds.includes(
497+
row.original.id
498+
)}
499+
onSelectionChange={handleRowSelect}
500+
index={index}
501+
alwaysVisible={checkboxMode !== "hidden"}
502+
/>
494503
) : (
495504
flexRender(
496505
cell.column.columnDef.cell,

0 commit comments

Comments
 (0)