Fix username field

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2020-05-19 12:12:14 +02:00 committed by Alexandre Bodin
parent f73d4fc226
commit d4833d3767
3 changed files with 28 additions and 1 deletions

View File

@ -27,6 +27,8 @@ const reducer = (state, action) =>
case 'ON_CHANGE': {
if (action.inputType === 'password' && !action.value) {
unset(draftState.modifiedData, action.keys.split('.'));
} else if (action.keys.includes('username')) {
set(draftState.modifiedData, action.keys.split('.'), null);
} else {
set(draftState.modifiedData, action.keys.split('.'), action.value);
}

View File

@ -151,6 +151,31 @@ describe('ADMIN | CONTAINERS | ProfilePage | reducer', () => {
expect(reducer(initialState, action)).toEqual(expected);
});
it('should set the username value to null if the value is empty', () => {
const initialState = {
modifiedData: {
email: 'john@strapi.io',
password: 'pwd123',
username: 'test',
},
};
const action = {
type: 'ON_CHANGE',
keys: 'username',
inputType: 'text',
value: '',
};
const expected = {
modifiedData: {
email: 'john@strapi.io',
password: 'pwd123',
username: null,
},
};
expect(reducer(initialState, action)).toEqual(expected);
});
});
describe('ON_SUBMIT', () => {

View File

@ -8,7 +8,7 @@ const schema = yup.object().shape({
.string()
.email(translatedErrors.email)
.required(translatedErrors.required),
username: yup.string(),
username: yup.string().nullable(),
password: yup
.string()
.min(8, translatedErrors.minLength)