Skip to content

Commit

Permalink
task: added helper function to pluralize words
Browse files Browse the repository at this point in the history
  • Loading branch information
finnar-bin committed Feb 21, 2024
1 parent bf539f9 commit 698205c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/shell/components/InviteMembersModal/ConfirmationDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ErrorRoundedIcon from "@mui/icons-material/ErrorRounded";
import CheckRoundedIcon from "@mui/icons-material/CheckRounded";
import CheckCircleRoundedIcon from "@mui/icons-material/CheckCircleRounded";
import CheckCircleIcon from "@mui/icons-material/CheckCircle";
import pluralizeWord from "../../../utility/pluralizeWord";

type ConfirmationModalProps = {
sentEmails: string[];
Expand All @@ -40,15 +41,23 @@ export const ConfirmationModal = ({
if (hasFailedInvites && hasSuccessfulInvites) {
return `Invites set to ${Object.keys(failedInvites).length} out of ${
Object.keys(failedInvites).length + sentEmails.length
} users (via email)`;
} ${pluralizeWord(
"user",
Object.keys(failedInvites).length + sentEmails.length
)} (via email)`;
}

if (hasFailedInvites && !hasSuccessfulInvites) {
return `Unable to invite ${Object.keys(failedInvites).length} users`;
return `Unable to invite ${
Object.keys(failedInvites).length
} ${pluralizeWord("user", Object.keys(failedInvites).length)}`;
}

if (!hasFailedInvites && hasSuccessfulInvites) {
return `Invite sent to ${sentEmails.length} users (via email)`;
return `Invite sent to ${pluralizeWord(
"user",
sentEmails.length
)} (via email)`;
}
};

Expand All @@ -65,7 +74,9 @@ export const ConfirmationModal = ({
display: "block",
}}
/>
<Box sx={{ mt: 1.5 }}>{generateHeaderText()}</Box>
<Typography variant="h5" fontWeight={700} sx={{ mt: 1.5 }}>
{generateHeaderText()}
</Typography>

<Typography sx={{ mt: 1 }} variant="body2" color="text.secondary">
See list below
Expand Down
3 changes: 3 additions & 0 deletions src/utility/pluralizeWord.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default (word: string, count: number) => {
return count > 1 ? `${word}s` : word;
};

0 comments on commit 698205c

Please sign in to comment.