Skip to content

Commit 169d41c

Browse files
committed
fix: move body to ternary
1 parent 94907f2 commit 169d41c

File tree

1 file changed

+22
-33
lines changed

1 file changed

+22
-33
lines changed

site/src/components/Alert/ErrorAlert.tsx

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,30 @@ export const ErrorAlert: FC<
1515
// not make sense in the FE to showing them duplicated
1616
const shouldDisplayDetail = message !== detail;
1717

18-
const body = () => {
19-
// When the error is a Forbidden response we include a link for the user to
20-
// go back to a known viewable page.
21-
// Additionally since the error messages and details from the server can be
22-
// missing or confusing for an end user we render a friendlier message
23-
// regardless of the response from the server.
24-
if (status === 403) {
25-
return (
26-
<>
27-
<AlertTitle>{message}</AlertTitle>
28-
<AlertDetail>
29-
{detail}{" "}
30-
<Link href="/workspaces" className="w-fit">
31-
Go to workspaces
32-
</Link>
33-
</AlertDetail>
34-
</>
35-
);
36-
}
37-
38-
if (detail) {
39-
return (
40-
<>
41-
<AlertTitle>{message}</AlertTitle>
42-
{shouldDisplayDetail && <AlertDetail>{detail}</AlertDetail>}
43-
</>
44-
);
45-
}
46-
47-
return message;
48-
};
49-
5018
return (
5119
<Alert severity="error" {...alertProps}>
52-
{body()}
20+
{
21+
// When the error is a Forbidden response we include a link for the user to
22+
// go back to a known viewable page.
23+
status === 403 ? (
24+
<>
25+
<AlertTitle>{message}</AlertTitle>
26+
<AlertDetail>
27+
{detail}{" "}
28+
<Link href="/workspaces" className="w-fit">
29+
Go to workspaces
30+
</Link>
31+
</AlertDetail>
32+
</>
33+
) : detail ? (
34+
<>
35+
<AlertTitle>{message}</AlertTitle>
36+
{shouldDisplayDetail && <AlertDetail>{detail}</AlertDetail>}
37+
</>
38+
) : (
39+
message
40+
)
41+
}
5342
</Alert>
5443
);
5544
};

0 commit comments

Comments
 (0)