ProfessionsPage: pluralize words using the lib "polish-plurals"

This commit is contained in:
Dawid Wysokiński 2021-04-11 11:40:54 +02:00
parent 1185b5f0de
commit 5645d4e9f3
3 changed files with 16 additions and 3 deletions

View File

@ -8,6 +8,7 @@ import {
withDefault,
} from 'use-query-params';
import { useSnackbar } from 'notistack';
import { polishPlurals } from 'polish-plurals';
import SortParam, { decodeSort } from 'libs/serialize-query-params/SortParam';
import { useScrollToElement } from 'libs/hooks';
import useProfessions from './ProfessionsPage.useProfessions';
@ -210,7 +211,12 @@ const ProfessionsPage = () => {
<Snackbar
open={selectedProfessions.length > 0}
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
message={`Wybrane zawody: ${selectedProfessions.length}`}
message={`Wybrano ${selectedProfessions.length} ${polishPlurals(
'zawód',
'zawody',
'zawodów',
selectedProfessions.length
)}`}
action={
<>
<Button onClick={handleDeleteProfessions} color="secondary">

View File

@ -1,5 +1,6 @@
import { useForm } from 'react-hook-form';
import { pick } from 'lodash';
import { polishPlurals } from 'polish-plurals';
import { MAX_NAME_LENGTH } from './constants';
import { ProfessionInput } from 'libs/graphql/types';
@ -58,7 +59,12 @@ const Form = ({ onClose, profession, onSubmit }: FormDialogProps) => {
required: 'Te pole jest wymagane.',
maxLength: {
value: MAX_NAME_LENGTH,
message: `Maksymalna długość nazwy zawodu to ${MAX_NAME_LENGTH} znaki.`,
message: `Maksymalna długość nazwy zawodu to ${MAX_NAME_LENGTH} ${polishPlurals(
'znak',
'znaki',
'znaków',
MAX_NAME_LENGTH
)}.`,
},
})}
error={!!errors.name}

View File

@ -61,8 +61,9 @@ const FormDialog = ({ open, onClose, user, onSubmit }: FormDialogProps) => {
return (
<Dialog
open={open}
onClose={isSubmitting ? undefined : onClose}
onClose={onClose}
fullWidth
disableBackdropClick={isSubmitting}
maxWidth="xs"
>
<form onSubmit={handleSubmit(_onSubmit)}>