Trim group titles when creating or editing
* Trim group titles when creating or editing * Trim title in more places
This commit is contained in:
parent
2cd29e1b63
commit
80e3582d01
3 changed files with 31 additions and 7 deletions
|
@ -55,9 +55,11 @@ export const EditConversationAttributesModal: FunctionComponent<PropsType> = ({
|
||||||
const [avatar, setAvatar] = useState<undefined | ArrayBuffer>(
|
const [avatar, setAvatar] = useState<undefined | ArrayBuffer>(
|
||||||
externalAvatarPath ? TEMPORARY_AVATAR_VALUE : undefined
|
externalAvatarPath ? TEMPORARY_AVATAR_VALUE : undefined
|
||||||
);
|
);
|
||||||
const [title, setTitle] = useState(externalTitle);
|
const [rawTitle, setRawTitle] = useState(externalTitle);
|
||||||
const [hasAvatarChanged, setHasAvatarChanged] = useState(false);
|
const [hasAvatarChanged, setHasAvatarChanged] = useState(false);
|
||||||
|
|
||||||
|
const trimmedTitle = rawTitle.trim();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const startingAvatarPath = startingAvatarPathRef.current;
|
const startingAvatarPath = startingAvatarPathRef.current;
|
||||||
if (!startingAvatarPath) {
|
if (!startingAvatarPath) {
|
||||||
|
@ -90,14 +92,14 @@ export const EditConversationAttributesModal: FunctionComponent<PropsType> = ({
|
||||||
const hasChangedExternally =
|
const hasChangedExternally =
|
||||||
startingAvatarPathRef.current !== externalAvatarPath ||
|
startingAvatarPathRef.current !== externalAvatarPath ||
|
||||||
startingTitleRef.current !== externalTitle;
|
startingTitleRef.current !== externalTitle;
|
||||||
const hasTitleChanged = title !== externalTitle;
|
const hasTitleChanged = trimmedTitle !== externalTitle.trim();
|
||||||
|
|
||||||
const isRequestActive = requestState === RequestState.Active;
|
const isRequestActive = requestState === RequestState.Active;
|
||||||
|
|
||||||
const canSubmit =
|
const canSubmit =
|
||||||
!isRequestActive &&
|
!isRequestActive &&
|
||||||
(hasChangedExternally || hasTitleChanged || hasAvatarChanged) &&
|
(hasChangedExternally || hasTitleChanged || hasAvatarChanged) &&
|
||||||
title.length > 0;
|
trimmedTitle.length > 0;
|
||||||
|
|
||||||
const onSubmit: FormEventHandler<HTMLFormElement> = event => {
|
const onSubmit: FormEventHandler<HTMLFormElement> = event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -110,7 +112,7 @@ export const EditConversationAttributesModal: FunctionComponent<PropsType> = ({
|
||||||
request.avatar = avatar;
|
request.avatar = avatar;
|
||||||
}
|
}
|
||||||
if (hasTitleChanged) {
|
if (hasTitleChanged) {
|
||||||
request.title = title;
|
request.title = trimmedTitle;
|
||||||
}
|
}
|
||||||
makeRequest(request);
|
makeRequest(request);
|
||||||
};
|
};
|
||||||
|
@ -150,8 +152,8 @@ export const EditConversationAttributesModal: FunctionComponent<PropsType> = ({
|
||||||
<GroupTitleInput
|
<GroupTitleInput
|
||||||
disabled={isRequestActive}
|
disabled={isRequestActive}
|
||||||
i18n={i18n}
|
i18n={i18n}
|
||||||
onChangeValue={setTitle}
|
onChangeValue={setRawTitle}
|
||||||
value={title}
|
value={rawTitle}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{requestState === RequestState.InactiveWithError && (
|
{requestState === RequestState.InactiveWithError && (
|
||||||
|
|
|
@ -731,7 +731,7 @@ function createGroup(): ThunkAction<
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const conversation = await groups.createGroupV2({
|
const conversation = await groups.createGroupV2({
|
||||||
name: composer.groupName,
|
name: composer.groupName.trim(),
|
||||||
avatar: composer.groupAvatar,
|
avatar: composer.groupAvatar,
|
||||||
conversationIds: composer.selectedConversationIds,
|
conversationIds: composer.selectedConversationIds,
|
||||||
});
|
});
|
||||||
|
|
|
@ -743,6 +743,28 @@ describe('both/state/ducks/conversations', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("trims the group's title before calling groups.createGroupV2", async () => {
|
||||||
|
await createGroup()(
|
||||||
|
sinon.spy(),
|
||||||
|
() => ({
|
||||||
|
...getEmptyRootState(),
|
||||||
|
conversations: {
|
||||||
|
...conversationsState,
|
||||||
|
composer: {
|
||||||
|
...conversationsState.composer,
|
||||||
|
groupName: ' To Trim \t',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
sinon.assert.calledWith(
|
||||||
|
createGroupStub,
|
||||||
|
sinon.match({ name: 'To Trim' })
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('dispatches a CREATE_GROUP_REJECTED action if group creation fails, which marks the state with an error', async () => {
|
it('dispatches a CREATE_GROUP_REJECTED action if group creation fails, which marks the state with an error', async () => {
|
||||||
createGroupStub.rejects(new Error('uh oh'));
|
createGroupStub.rejects(new Error('uh oh'));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue