Skip to content

Commit

Permalink
Merge pull request #61 from 001elijah/create-edit-modal
Browse files Browse the repository at this point in the history
fix max-length column, cirilica
  • Loading branch information
001elijah committed Jun 29, 2023
2 parents 15b73ba + b870398 commit 6b5a608
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 12 deletions.
18 changes: 15 additions & 3 deletions src/components/BoardModalWindow/BoardModalWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const BoardModalWindow = ({
const [background, setBackground] = useState();
const [icon, setIcon] = useState('');
const [isValid, setIsValid] = useState(false);
// const [errorTitleMaxLength, setErrorTitleMaxLength] = useState(false);
const [errorTitleMaxLength, setErrorTitleMaxLength] = useState(false);
const [errorCirillicaTitle, setErrorCirillicaTitle] = useState(false);

const handleSubmit = e => {
Expand All @@ -46,7 +46,7 @@ export const BoardModalWindow = ({
};

const handleChange = e => {
const cyrillicRegex = /^[a-zA-Z]+$/;
const cyrillicRegex = /^[^\u0400-\u04FF]+$/;
setTitle(e.target.value);

if (e.target.value.length > 0 && !cyrillicRegex.test(e.target.value)) {
Expand All @@ -55,6 +55,12 @@ export const BoardModalWindow = ({
} else {
setErrorCirillicaTitle(false);
}

if (e.target.value.length === 64) {
setErrorTitleMaxLength(true);
} else {
setErrorTitleMaxLength(false);
}
};

return (
Expand All @@ -64,10 +70,16 @@ export const BoardModalWindow = ({
className={`${s.inputModal} ${s[theme]}`}
value={title}
placeholder={'Title'}
maxLength="64"
onChange={handleChange}
/>
{isValid && <p className={s.errorTitle}>required field</p>}
{errorCirillicaTitle && (
{errorTitleMaxLength && (
<p className={s.errorTitleMaxLength}>
you have reached the symbols limit
</p>
)}
{errorCirillicaTitle && !errorTitleMaxLength && (
<p className={s.errorCirillicaTitle}>
invalid characters (latin alphabet only)
</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import '../../assets/styles/vars';
@import '../../assets/styles/mixins';

.errorTitleMaxLength,
.errorCirillicaTitle,
.errorTitle {
position: absolute;
Expand Down
4 changes: 2 additions & 2 deletions src/components/CardModalWindow/CardModalWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const CardModalWindow = ({
};

const handleChange = e => {
const cyrillicRegex = /^[a-zA-Z]+$/;
const cyrillicRegex = /^[^\u0400-\u04FF]+$/;
setValue(e.target.value);

if (e.target.value.length > 0 && !cyrillicRegex.test(e.target.value)) {
Expand All @@ -77,7 +77,7 @@ export const CardModalWindow = ({
};

const handleChangeDescription = e => {
const cyrillicRegex = /^[a-zA-Z]+$/;
const cyrillicRegex = /^[^\u0400-\u04FF]+$/;
setComent(e.target.value);

if (e.target.value.length > 0 && !cyrillicRegex.test(e.target.value)) {
Expand Down
18 changes: 16 additions & 2 deletions src/components/ColumnModalWindow/ColumnModalWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const ColumnModalWindow = ({
const theme = useSelector(selectorTheme);
const [isValid, setIsValid] = useState(false);
const [errorCirillicaTitle, setErrorCirillicaTitle] = useState(false);
const [errorTitleMaxLength, setErrorTitleMaxLength] = useState(false);

// const updateBoard = ()=>{
// setTimeout(()=>{dispatch(getBoardById(boardId)),0 })
Expand Down Expand Up @@ -55,14 +56,21 @@ export const ColumnModalWindow = ({
};

const handleChange = e => {
const cyrillicRegex = /^[a-zA-Z]+$/;
const cyrillicRegex = /^[^\u0400-\u04FF]+$/;

if (e.target.value.length > 0 && !cyrillicRegex.test(e.target.value)) {
setErrorCirillicaTitle(true);
e.preventDefault();
} else {
setErrorCirillicaTitle(false);
}

if (e.target.value.length === 64) {
setErrorTitleMaxLength(true);
} else {
setErrorTitleMaxLength(false);
}

setValue(e.target.value);
};
return (
Expand All @@ -72,10 +80,16 @@ export const ColumnModalWindow = ({
className={`${s.inputModal} ${s[theme]}`}
value={value}
placeholder="Title"
maxLength="64"
onChange={handleChange}
/>
{isValid && <p className={s.errorTitle}>required field</p>}
{errorCirillicaTitle && (
{errorTitleMaxLength && (
<p className={s.errorTitleMaxLength}>
you have reached the symbols limit
</p>
)}
{errorCirillicaTitle && !errorTitleMaxLength && (
<p className={s.errorCirillicaTitle}>
invalid characters (latin alphabet only)
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
}
}

.errorTitleMaxLength,
.errorCirillicaTitle,
.errorTitle {
position: absolute;
Expand Down
10 changes: 5 additions & 5 deletions src/components/SchemaValidation/schemaValidation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export const validationSchemaRegister = yup.object().shape({
userName: yup
.string()
.matches(
/^[a-zA-Z0-9]+([-_ ][a-zA-Z0-9]+)*$/,
// 'Only letters, numbers, underscores, spaces, hyphens, and dashes are allowed between words',
'Invalid name'
)
/^[a-zA-Z0-9]+([-_ ][a-zA-Z0-9]+)*$/,
// 'Only letters, numbers, underscores, spaces, hyphens, and dashes are allowed between words',
'Invalid name',
)
.min(2, 'Minimum length 2 characters')
.max(32, 'Maximum length 32 characters')
.required('Name required'),
Expand All @@ -48,4 +48,4 @@ export const validationSchemaRegister = yup.object().shape({
.min(8, 'Minimum length 8 characters')
.max(64, 'Maximum length 64 characters')
.required('Password required'),
});
});

0 comments on commit 6b5a608

Please sign in to comment.