Skip to content

Commit 8ee7656

Browse files
committed
error fixed
1 parent bbd795f commit 8ee7656

3 files changed

Lines changed: 52 additions & 47 deletions

File tree

src/components/BMDashboard/Equipment/List/EquipmentListModal.jsx

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ function EquipmentListModal({ modal, setModal, record, recordType }) {
66
if (!record) return null;
77

88
const toggle = () => setModal(false);
9+
const renderUser = user => {
10+
if (!user) {
11+
return <span>-</span>;
12+
}
13+
14+
const fullName = [user.firstName, user.lastName].filter(Boolean).join(' ') || 'Unknown User';
15+
16+
if (!user._id) {
17+
return <span>{fullName}</span>;
18+
}
19+
20+
return <a href={`/userprofile/${user._id}`}>{fullName}</a>;
21+
};
922

1023
const headerTitle =
1124
{
@@ -33,15 +46,7 @@ function EquipmentListModal({ modal, setModal, record, recordType }) {
3346
{(record.updateRecord || []).map(data => (
3447
<tr key={data._id}>
3548
<td>{moment.utc(data.date).format('LL')}</td>
36-
<td>
37-
{data.createdBy ? (
38-
<a href={`/userprofile/${data.createdBy._id}`}>
39-
{`${data.createdBy.firstName} ${data.createdBy.lastName}`}
40-
</a>
41-
) : (
42-
<span>-</span>
43-
)}
44-
</td>
49+
<td>{renderUser(data.createdBy)}</td>
4550
</tr>
4651
))}
4752
</tbody>
@@ -64,15 +69,7 @@ function EquipmentListModal({ modal, setModal, record, recordType }) {
6469
<td>{moment.utc(data.date).format('LL')}</td>
6570
<td>{data.status || '-'}</td>
6671
<td>{data.quantity || '-'}</td>
67-
<td>
68-
{data.requestedBy ? (
69-
<a href={`/userprofile/${data.requestedBy._id}`}>
70-
{`${data.requestedBy.firstName} ${data.requestedBy.lastName}`}
71-
</a>
72-
) : (
73-
<span>-</span>
74-
)}
75-
</td>
72+
<td>{renderUser(data.requestedBy)}</td>
7673
</tr>
7774
))}
7875
</tbody>

src/components/BMDashboard/ItemList/RecordsModal.jsx

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ export function Record({ record, recordType, setRecord }) {
6969
if (value == null) return '-';
7070
return unit ? `${value} ${unit}` : `${value}`;
7171
};
72+
const renderUser = user => {
73+
if (!user) {
74+
return <span>-</span>;
75+
}
76+
77+
const fullName = [user.firstName, user.lastName].filter(Boolean).join(' ') || 'Unknown User';
78+
79+
if (!user._id) {
80+
return <span>{fullName}</span>;
81+
}
82+
83+
return (
84+
<a href={`/userprofile/${user._id}`} className={darkMode ? styles.blue_link : ''}>
85+
{fullName}
86+
</a>
87+
);
88+
};
7289

7390
const handleApprove = async (purchaseId, quantity) => {
7491
try {
@@ -122,15 +139,8 @@ export function Record({ record, recordType, setRecord }) {
122139
<td>{moment.utc(data.date).format('LL')}</td>
123140
<td>{formatQuantity(data.quantityUsed, record.itemType?.unit)}</td>
124141
<td>{formatQuantity(data.quantityWasted, record.itemType?.unit)}</td>
125-
<td>
126-
<a
127-
href={`/userprofile/${data.createdBy._id}`}
128-
className={darkMode ? styles.blue_link : ''}
129-
>
130-
{`${data.createdBy.firstName} ${data.createdBy.lastName}`}
131-
</a>
132-
</td>
133-
<td>{data?.createdBy?.email}</td>
142+
<td>{renderUser(data.createdBy)}</td>
143+
<td>{data?.createdBy?.email || '-'}</td>
134144
</tr>
135145
))
136146
) : (
@@ -169,15 +179,8 @@ export function Record({ record, recordType, setRecord }) {
169179
<td>{priority}</td>
170180
<td>{brandPref}</td>
171181
<td>{quantity || '-'}</td>
172-
<td>
173-
<a
174-
href={`/userprofile/${requestedBy._id}`}
175-
className={darkMode ? styles.blue_link : ''}
176-
>
177-
{`${requestedBy.firstName} ${requestedBy.lastName}`}
178-
</a>
179-
</td>
180-
<td>{requestedBy.email}</td>
182+
<td>{renderUser(requestedBy)}</td>
183+
<td>{requestedBy?.email || '-'}</td>
181184
<td>{moment(date).format('MM/DD/YY')}</td>
182185
<td>{status}</td>
183186
<td>

src/components/BMDashboard/ToolItemList/ToolRecordsModal.jsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ export default function RecordsModal({ modal, setModal, record, setRecord, recor
3030
}
3131

3232
export function Record({ record, recordType }) {
33+
const renderUser = user => {
34+
if (!user) {
35+
return <span>-</span>;
36+
}
37+
38+
const fullName = [user.firstName, user.lastName].filter(Boolean).join(' ') || 'Unknown User';
39+
40+
if (!user._id) {
41+
return <span>{fullName}</span>;
42+
}
43+
44+
return <a href={`/userprofile/${user._id}`}>{fullName}</a>;
45+
};
46+
3347
if (recordType === 'Update') {
3448
return (
3549
<>
@@ -47,12 +61,7 @@ export function Record({ record, recordType }) {
4761
<tr key={index}>
4862
<td>{moment.utc(data.date).format('LL')}</td>
4963
<td>{data.condition}</td>
50-
<td>
51-
<a href={`/userprofile/${data.createdBy._id}`}>
52-
{`${data.createdBy?.firstName || 'Unknown'}
53-
${data.createdBy?.lastName || 'Unknown'}`}
54-
</a>
55-
</td>
64+
<td>{renderUser(data.createdBy)}</td>
5665
</tr>
5766
);
5867
})}
@@ -82,11 +91,7 @@ export function Record({ record, recordType }) {
8291
<td>{priority}</td>
8392
<td>{makeModelPref}</td>
8493
<td>{quantity || '-'}</td>
85-
<td>
86-
<a href={`/userprofile/${requestedBy?._id}`}>
87-
{`${requestedBy?.firstName || 'Unknown'} ${requestedBy?.lastName || 'User'}`}
88-
</a>
89-
</td>
94+
<td>{renderUser(requestedBy)}</td>
9095
<td>{moment(date).format('MM/DD/YY')}</td>
9196
<td>{status}</td>
9297
<td>{usageDesc}</td>

0 commit comments

Comments
 (0)