-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMPROVE] Rewrite contextualbar RoomMembers - AddUsers as React Compo…
…nent (#19803) Co-authored-by: Guilherme Gazzo <guilherme@gazzo.xyz>
- Loading branch information
Showing
12 changed files
with
144 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import './flexTabBar.html'; | ||
import './tabs/inviteUsers.html'; | ||
import './tabs/membersList.html'; | ||
import './tabs/uploadedFilesList.html'; | ||
import './flexTabBar'; | ||
import './tabs/inviteUsers'; | ||
import './tabs/membersList'; | ||
import './tabs/uploadedFilesList'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import React from 'react'; | ||
|
||
import AutoComplete from './AutoComplete'; | ||
import { UserAutoComplete } from './AutoComplete'; | ||
|
||
export default { | ||
title: 'components/AutoComplete', | ||
component: AutoComplete, | ||
component: UserAutoComplete, | ||
}; | ||
|
||
export const Example = () => <AutoComplete/>; | ||
export const Example = () => <UserAutoComplete/>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
client/views/room/contextualBar/RoomMembers/AddUsers/AddUsers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import React, { useState } from 'react'; | ||
import { Field, Button } from '@rocket.chat/fuselage'; | ||
import { useMutableCallback } from '@rocket.chat/fuselage-hooks'; | ||
|
||
import UserAutoCompleteMultiple from '../../../../../../ee/client/audit/UserAutoCompleteMultiple'; | ||
import VerticalBar from '../../../../../components/VerticalBar'; | ||
import { useTranslation } from '../../../../../contexts/TranslationContext'; | ||
import { useForm } from '../../../../../hooks/useForm'; | ||
import { useMethod } from '../../../../../contexts/ServerContext'; | ||
import { useToastMessageDispatch } from '../../../../../contexts/ToastMessagesContext'; | ||
|
||
export const AddUsers = ({ | ||
onClickClose, | ||
onClickBack, | ||
onClickSave, | ||
value, | ||
onChange, | ||
errors, | ||
}) => { | ||
const t = useTranslation(); | ||
|
||
return ( | ||
<> | ||
<VerticalBar.Header> | ||
{onClickBack && <VerticalBar.Back onClick={onClickBack} />} | ||
<VerticalBar.Text>{t('Add_users')}</VerticalBar.Text> | ||
{onClickClose && <VerticalBar.Close onClick={onClickClose} />} | ||
</VerticalBar.Header> | ||
<VerticalBar.ScrollableContent> | ||
<Field > | ||
<Field.Label flexGrow={0}>{t('Choose_users')}</Field.Label> | ||
<UserAutoCompleteMultiple errors={errors.users} value={value} onChange={onChange} placeholder={t('Choose_users')} /> | ||
{errors.users && <Field.Error> | ||
{errors.users} | ||
</Field.Error>} | ||
</Field> | ||
</VerticalBar.ScrollableContent> | ||
<VerticalBar.Footer> | ||
<Button primary disabled={!value || value.length === 0} onClick={onClickSave}>{t('Add_users')}</Button> | ||
</VerticalBar.Footer> | ||
</> | ||
); | ||
}; | ||
|
||
export default ({ | ||
rid, | ||
tabBar, | ||
onClickBack, | ||
}) => { | ||
const t = useTranslation(); | ||
const dispatchToastMessage = useToastMessageDispatch(); | ||
const [errors, setErrors] = useState({}); | ||
|
||
const onClickClose = useMutableCallback(() => tabBar && tabBar.close()); | ||
const saveAction = useMethod('addUsersToRoom'); | ||
|
||
const { values, handlers } = useForm({ users: [] }); | ||
const { users } = values; | ||
const { handleUsers } = handlers; | ||
|
||
const onChangeUsers = useMutableCallback((value, action) => { | ||
if (!action) { | ||
if (users.includes(value)) { | ||
return; | ||
} | ||
return handleUsers([...users, value]); | ||
} | ||
handleUsers(users.filter((current) => current !== value)); | ||
}); | ||
|
||
const handleSave = useMutableCallback(async () => { | ||
if (users.length < 1) { | ||
return setErrors({ | ||
users: t('Select_at_least_one_user'), | ||
}); | ||
} | ||
|
||
try { | ||
await saveAction({ rid, users }); | ||
dispatchToastMessage({ type: 'success', message: t('Users_added') }); | ||
onClickBack(); | ||
} catch (e) { | ||
dispatchToastMessage({ type: 'error', message: e }); | ||
} | ||
|
||
setErrors({}); | ||
}); | ||
|
||
return ( | ||
<AddUsers | ||
onClickClose={onClickClose} | ||
onClickBack={onClickBack} | ||
onClickSave={handleSave} | ||
value={users} | ||
onChange={onChangeUsers} | ||
errors={errors} | ||
/> | ||
); | ||
}; |
29 changes: 29 additions & 0 deletions
29
client/views/room/contextualBar/RoomMembers/AddUsers/AddUsers.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
|
||
import { AddUsers } from './AddUsers'; | ||
import VerticalBar from '../../../../../components/VerticalBar'; | ||
|
||
export default { | ||
title: 'components/RoomMembers/AddUsers', | ||
component: AddUsers, | ||
}; | ||
|
||
export const Default = () => <VerticalBar> | ||
<AddUsers | ||
onClickBack={alert} | ||
onClickClose={alert} | ||
onClickSave={alert} | ||
value={[]} | ||
errors={{}} | ||
/> | ||
</VerticalBar>; | ||
|
||
export const Error = () => <VerticalBar> | ||
<AddUsers | ||
onClickBack={alert} | ||
onClickClose={alert} | ||
onClickSave={alert} | ||
value={[]} | ||
errors={{ users: 'With Test Error' }} | ||
/> | ||
</VerticalBar>; |
3 changes: 3 additions & 0 deletions
3
client/views/room/contextualBar/RoomMembers/AddUsers/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import AddUsers from './AddUsers'; | ||
|
||
export default AddUsers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.