Enforce userName and title can only containing aphlanumeric and dashes

Enforce data integrity basically, important since they're used for urls
I could do url encoding, but the idea is the the url looks good so
its helping keep the feel of the website
This commit is contained in:
Kurt Hutten
2020-11-08 17:56:08 +11:00
parent 5034cf98c3
commit 8107c7dcea
6 changed files with 16 additions and 9 deletions

View File

@@ -41,9 +41,10 @@ const UserProfile = ({user, isEditable, loading, onSave, error}) => {
/>
</div>
<div className="ml-6 flex flex-col justify-between">
<ProfileTextInput fields={editableTextFields} onChange={(textFields) => setInput({
<ProfileTextInput fields={editableTextFields} onChange={({userName, name}) => setInput({
...input,
...textFields,
name,
userName: userName.replace(/([^a-zA-Z\d_:])/g, '-'),
})} isEditable={isEditable}/>
{isEditable ?
<Button className="bg-indigo-200" iconName="plus" onClick={() => onSave(user.userName, input)}>Save Profile</Button> : // TODO replace pencil with a save icon