Skip to content

Commit b3f1772

Browse files
authored
feat: add max length reached warning (#64)
* feat: add max length reached warning Signed-off-by: romanetar <roman_ag@hotmail.com> * fix: extract input length limit to a constant Signed-off-by: romanetar <roman_ag@hotmail.com> --------- Signed-off-by: romanetar <roman_ag@hotmail.com>
1 parent acddb9b commit b3f1772

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

resources/js/oauth2/profile/edit_client/components/form_controls.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, {useState} from "react";
22
import {makeStyles, withStyles} from '@material-ui/core/styles';
33
import {
44
Checkbox,
@@ -44,28 +44,43 @@ const TooltipLabel = ({id, title, tooltip}) => (
4444
</FormLabel>
4545
);
4646

47-
export const SimpleTextFormControl = ({id, title, tooltip, type, value, touched, errors, maxLength, onChange}) => (
48-
<FormControl variant="outlined" className={styles.form_control}>
47+
export const SimpleTextFormControl = ({id, title, tooltip, type, value, touched, errors, maxLength, onChange}) => {
48+
const SIMPLE_INPUT_MAX_LENGTH = (maxLength ?? 100) + 1;
49+
const [text, setText] = useState('');
50+
51+
const handleChange = (e) => {
52+
setText(e.target.value);
53+
if (onChange) onChange(e);
54+
};
55+
56+
const isLimitExceeded = text.length > maxLength;
57+
58+
return <FormControl variant="outlined" className={styles.form_control}>
4959
<TooltipLabel id={id} title={title} tooltip={tooltip}/>
5060
<TextField
5161
id={id}
5262
name={id}
5363
variant="outlined"
5464
fullWidth
5565
size="small"
56-
inputProps={{maxLength: maxLength ?? 100}}
66+
inputProps={{maxLength: SIMPLE_INPUT_MAX_LENGTH}}
5767
autoFocus={true}
5868
value={value}
59-
onChange={onChange}
69+
onChange={handleChange}
6070
type={type}
6171
error={
6272
touched &&
6373
Boolean(errors)
6474
}
6575
helperText={touched && errors}
6676
/>
77+
{isLimitExceeded &&
78+
<div className={styles.error_label}>
79+
{`Cannot exceed max length (${maxLength} chars)`}
80+
</div>
81+
}
6782
</FormControl>
68-
);
83+
};
6984

7085
export const SelectFormControl = ({id, title, tooltip, value, touched, errors, onChange, options}) => (
7186
<FormControl variant="outlined" className={styles.form_control}>

resources/js/oauth2/profile/edit_client/components/oauth_panel.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ const OauthPanel = ({
3838
onRefreshTokenChange,
3939
onSavePromise
4040
}) => {
41+
const SIMPLE_INPUT_MAX_LENGTH = 255;
42+
4143
const {application_type, client_type, is_own} = entity;
4244
const {can_request_refresh_tokens} = initialValues;
4345

@@ -85,6 +87,10 @@ const OauthPanel = ({
8587
app_description: string("The app description field is required.").required(
8688
"The app description field is required."
8789
),
90+
website: string().max(SIMPLE_INPUT_MAX_LENGTH, ''),
91+
logo_uri: string().max(SIMPLE_INPUT_MAX_LENGTH, ''),
92+
tos_uri: string().max(SIMPLE_INPUT_MAX_LENGTH, ''),
93+
policy_uri: string().max(SIMPLE_INPUT_MAX_LENGTH, ''),
8894
});
8995
}
9096

@@ -282,7 +288,7 @@ const OauthPanel = ({
282288
title="Application Web Site Url (optional)"
283289
tooltip="Client home page URL."
284290
type="url"
285-
maxLength={255}
291+
maxLength={SIMPLE_INPUT_MAX_LENGTH}
286292
value={formik.values.website ?? ''}
287293
touched={formik.touched.website}
288294
errors={formik.errors.website}
@@ -293,7 +299,7 @@ const OauthPanel = ({
293299
title="Application Logo Url (optional)"
294300
tooltip="URL that references a logo for the Client application."
295301
type="url"
296-
maxLength={255}
302+
maxLength={SIMPLE_INPUT_MAX_LENGTH}
297303
value={formik.values.logo_uri ?? ''}
298304
touched={formik.touched.logo_uri}
299305
errors={formik.errors.logo_uri}
@@ -304,7 +310,7 @@ const OauthPanel = ({
304310
title="Application Term of Service Url (optional)"
305311
tooltip="URL that the Relying Party Client provides to the End-User to read about the Relying Party's terms of service."
306312
type="url"
307-
maxLength={255}
313+
maxLength={SIMPLE_INPUT_MAX_LENGTH}
308314
value={formik.values.tos_uri ?? ''}
309315
touched={formik.touched.tos_uri}
310316
errors={formik.errors.tos_uri}
@@ -315,7 +321,7 @@ const OauthPanel = ({
315321
title="Application Policy Url (optional)"
316322
tooltip="URL that the Relying Party Client provides to the End-User to read about the how the profile data will be used."
317323
type="url"
318-
maxLength={255}
324+
maxLength={SIMPLE_INPUT_MAX_LENGTH}
319325
value={formik.values.policy_uri ?? ''}
320326
touched={formik.touched.policy_uri}
321327
errors={formik.errors.policy_uri}

0 commit comments

Comments
 (0)