Skip to content

Commit 6336fc9

Browse files
committed
Chore: Required form + add user to table locally
1 parent 7001320 commit 6336fc9

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

client/src/components/admin/AddPreview.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ const AddPreview = ({
5151
userType,
5252
isOpen,
5353
onClose,
54+
onUserAdded,
5455
}: {
5556
userType: RoleKey;
5657
isOpen: boolean;
5758
onClose: () => void;
59+
onUserAdded?: (newUser: UserInfo & { id: number }) => void;
5860
}) => {
5961
const { backend } = useBackendContext();
6062

@@ -95,8 +97,8 @@ const AddPreview = ({
9597
return;
9698
}
9799

98-
for (const value of Object.values(newUser)) {
99-
if (value === "") {
100+
for (const [key, value] of Object.entries(newUser)) {
101+
if (key !== "notes" && value === "") {
100102
toast({
101103
title: `Missing Information`,
102104
description: `There is a missing or incorrect field.`,
@@ -127,6 +129,14 @@ const AddPreview = ({
127129
date: new Date(),
128130
caloptimaFunded: false,
129131
});
132+
133+
// Add the new user to local state
134+
if (onUserAdded) {
135+
onUserAdded({
136+
...newUser,
137+
id: cm_id
138+
});
139+
}
130140
} catch (e) {
131141
console.error(e);
132142
}
@@ -257,7 +267,7 @@ const AddPreview = ({
257267
<Table variant="simple">
258268
<Tbody>
259269
<Tr>
260-
<Td fontSize="medium">First Name</Td>
270+
<Td fontSize="medium">First Name <Text as="span" color="red">*</Text></Td>
261271
<Td>
262272
<TextInputComponent
263273
name="firstName"
@@ -269,7 +279,7 @@ const AddPreview = ({
269279
</Td>
270280
</Tr>
271281
<Tr>
272-
<Td fontSize="medium">Last Name</Td>
282+
<Td fontSize="medium">Last Name <Text as="span" color="red">*</Text></Td>
273283
<Td>
274284
<TextInputComponent
275285
name="lastName"
@@ -281,7 +291,7 @@ const AddPreview = ({
281291
</Td>
282292
</Tr>
283293
<Tr>
284-
<Td fontSize="medium">Email</Td>
294+
<Td fontSize="medium">Email <Text as="span" color="red">*</Text></Td>
285295
<Td>
286296
<TextInputComponent
287297
name="email"
@@ -293,7 +303,7 @@ const AddPreview = ({
293303
</Td>
294304
</Tr>
295305
<Tr>
296-
<Td fontSize="medium">Location</Td>
306+
<Td fontSize="medium">Location <Text as="span" color="red">*</Text></Td>
297307
<Td>
298308
<SelectInputComponent
299309
name="location"
@@ -305,7 +315,7 @@ const AddPreview = ({
305315
</Td>
306316
</Tr>
307317
<Tr>
308-
<Td fontSize="medium">Phone</Td>
318+
<Td fontSize="medium">Phone <Text as="span" color="red">*</Text></Td>
309319
<Td>
310320
<TextInputComponent
311321
name="phoneNumber"

client/src/components/admin/ManageAccounts.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ export const ManageAccounts = () => {
135135
}
136136
};
137137

138+
const handleUserAdded = (newUser: Person) => {
139+
setPersons(prev => [...prev, { ...newUser, isChecked: false, isHovered: false }]);
140+
};
141+
138142
const handleDelete = async () => {
139143
try {
140144

@@ -594,6 +598,7 @@ export const ManageAccounts = () => {
594598
userType={view}
595599
isOpen={isOpen}
596600
onClose={onClose}
601+
onUserAdded={handleUserAdded}
597602
/>
598603
</VStack>
599604
);

0 commit comments

Comments
 (0)