MM-62550- trim value and create batch updates (#29895)
* trim value and create batch updates * update test * update for review comments --------- Co-authored-by: Caleb Roseland <caleb@calebroseland.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
0cca57b6df
Коммит
49948891ce
@@ -246,7 +246,7 @@ describe('components/user_settings/general/UserSettingsGeneral', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('submitAttribute() should have called saveCustomProfileAttribute', async () => {
|
test('submitAttribute() should have called saveCustomProfileAttribute', async () => {
|
||||||
const saveCustomProfileAttribute = jest.fn().mockResolvedValue({data: true});
|
const saveCustomProfileAttribute = jest.fn().mockResolvedValue({1: 'Updated Value'});
|
||||||
const props = {
|
const props = {
|
||||||
...requiredProps,
|
...requiredProps,
|
||||||
enableCustomProfileAttributes: true,
|
enableCustomProfileAttributes: true,
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ export type Props = {
|
|||||||
sendVerificationEmail: (email: string) => Promise<ActionResult>;
|
sendVerificationEmail: (email: string) => Promise<ActionResult>;
|
||||||
setDefaultProfileImage: (id: string) => void;
|
setDefaultProfileImage: (id: string) => void;
|
||||||
uploadProfileImage: (id: string, file: File) => Promise<ActionResult>;
|
uploadProfileImage: (id: string, file: File) => Promise<ActionResult>;
|
||||||
saveCustomProfileAttribute: (userID: string, attributeID: string, attributeValue: string) => Promise<ActionResult>;
|
saveCustomProfileAttribute: (userID: string, attributeID: string, attributeValue: string) => Promise<ActionResult<Record<string, string>>>;
|
||||||
getCustomProfileAttributeFields: () => Promise<ActionResult>;
|
getCustomProfileAttributeFields: () => Promise<ActionResult>;
|
||||||
};
|
};
|
||||||
requireEmailVerification?: boolean;
|
requireEmailVerification?: boolean;
|
||||||
@@ -429,6 +429,7 @@ export class UserSettingsGeneralTab extends PureComponent<Props, State> {
|
|||||||
then(({data, error: err}) => {
|
then(({data, error: err}) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
this.updateSection('');
|
this.updateSection('');
|
||||||
|
this.setState({customAttributeValues: {...this.state.customAttributeValues, ...data}});
|
||||||
} else if (err) {
|
} else if (err) {
|
||||||
const serverError = err;
|
const serverError = err;
|
||||||
this.setState({serverError, emailError: '', clientError: '', sectionIsSaving: false});
|
this.setState({serverError, emailError: '', clientError: '', sectionIsSaving: false});
|
||||||
|
|||||||
@@ -1712,7 +1712,7 @@ describe('Actions.Users', () => {
|
|||||||
|
|
||||||
const response = await store.dispatch(Actions.saveCustomProfileAttribute(currentUser.id, '123', ' NewValue '));
|
const response = await store.dispatch(Actions.saveCustomProfileAttribute(currentUser.id, '123', ' NewValue '));
|
||||||
const data = response.data!;
|
const data = response.data!;
|
||||||
expect(data).toBeTruthy();
|
expect(data).toEqual({123: 'NewValue'});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('checkForModifiedUsers', () => {
|
describe('checkForModifiedUsers', () => {
|
||||||
|
|||||||
@@ -970,15 +970,16 @@ export function updateMe(user: Partial<UserProfile>): ActionFuncAsync<UserProfil
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function saveCustomProfileAttribute(userID: string, attributeID: string, attributeValue: string): ActionFuncAsync {
|
export function saveCustomProfileAttribute(userID: string, attributeID: string, attributeValue: string): ActionFuncAsync<Record<string, string>> {
|
||||||
return async (dispatch) => {
|
return async (dispatch) => {
|
||||||
try {
|
try {
|
||||||
await Client4.updateCustomProfileAttributeValues(attributeID, attributeValue);
|
const values = {[attributeID]: attributeValue.trim()};
|
||||||
|
const data = await Client4.updateCustomProfileAttributeValues(values);
|
||||||
|
return {data};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
dispatch(logError(error));
|
dispatch(logError(error));
|
||||||
return {error};
|
return {error};
|
||||||
}
|
}
|
||||||
return {data: true};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2103,13 +2103,10 @@ export default class Client4 {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
updateCustomProfileAttributeValues = (attributeID: string, attributeValue: string) => {
|
updateCustomProfileAttributeValues = (attributeValues: Record<string, string>) => {
|
||||||
const obj: { [key: string]: string } = {};
|
|
||||||
obj[attributeID] = attributeValue;
|
|
||||||
|
|
||||||
return this.doFetch<Record<string, string>>(
|
return this.doFetch<Record<string, string>>(
|
||||||
`${this.getCustomProfileAttributeValuesRoute()}`,
|
`${this.getCustomProfileAttributeValuesRoute()}`,
|
||||||
{method: 'PATCH', body: JSON.stringify(obj)},
|
{method: 'PATCH', body: JSON.stringify(attributeValues)},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user