Skip to content

Commit

Permalink
Merge pull request #1003 from AletheiaFact/user-input-on-work-flow
Browse files Browse the repository at this point in the history
Fixed Conditional For Fetch on User Input
  • Loading branch information
thesocialdev committed Sep 15, 2023
2 parents 81a9968 + 1d62f70 commit bab16a7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/components/Form/UserInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@ const UserInput = ({

useEffect(() => {
const fetchUserNames = async () => {
if (Array.isArray(value) ? value.length > 0 : value !== "") {
if (
Array.isArray(value) ? value.length > 0 : value !== "" && value
) {
try {
setIsLoading(true);
const userPromises = Array.isArray(value)
? value.map((id) => userApi.getById(id))
: [userApi.getById(value)];
const users = await Promise.all(userPromises);
const treatedValues = users.map((user) => ({
label: user.name,
value: user._id,
label: user?.name,
value: user?._id,
}));
setTreatedValue(treatedValues);
} catch (error) {
Expand Down

0 comments on commit bab16a7

Please sign in to comment.