Skip to content

Commit 165b124

Browse files
committed
feat(workspace-settings): attach action to api
1 parent 037136e commit 165b124

File tree

6 files changed

+109
-117
lines changed

6 files changed

+109
-117
lines changed

src/common/components/navigation/header/settings/addNewMember.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {
22
Input,
33
Message,
44
Button,
5+
IconButton,
56
Label,
6-
MediaInput,
77
} from '@appquality/unguess-design-system';
88
import { Field } from '@zendeskgarden/react-forms';
99
import { Form, Formik, FormikProps, FormikValues } from 'formik';
@@ -21,6 +21,10 @@ const formInitialValues = {
2121
const EmailTextField = styled(Field)`
2222
display: flex;
2323
width: 100%;
24+
align-items: first baseline;
25+
button {
26+
margin-left: ${({ theme }) => theme.space.sm};
27+
}
2428
`;
2529

2630
export const AddNewMemberInput = () => {
@@ -30,16 +34,6 @@ export const AddNewMemberInput = () => {
3034

3135
if (!activeWorkspace) return null;
3236

33-
const handleValidation = (values: FormikValues) => {
34-
const errors: { email?: string } = {};
35-
if (!values.email) {
36-
errors.email = 'Required';
37-
} else if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(values.email)) {
38-
errors.email = 'Invalid email address';
39-
}
40-
return errors;
41-
};
42-
4337
const validationSchema = Yup.object().shape({
4438
email: Yup.string()
4539
.email(t('__WORKSPACE_SETTINGS_ADD_MEMBER_INVALID_EMAIL_ERROR'))
@@ -53,7 +47,6 @@ export const AddNewMemberInput = () => {
5347
validateOnBlur
5448
validationSchema={validationSchema}
5549
onSubmit={(values, actions) => {
56-
console.log('submit', values);
5750
addNewMember({
5851
wid: activeWorkspace?.id.toString() || '',
5952
body: {
@@ -75,7 +68,10 @@ export const AddNewMemberInput = () => {
7568
handleSubmit,
7669
...formProps
7770
}: FormikProps<{ email: string }>) => (
78-
<Form onSubmit={handleSubmit}>
71+
<Form
72+
onSubmit={handleSubmit}
73+
style={{ marginBottom: globalTheme.space.sm }}
74+
>
7975
<Label>{t('__WORKSPACE_SETTINGS_ADD_MEMBER_EMAIL_LABEL')}</Label>
8076
<EmailTextField>
8177
<Input
@@ -87,6 +83,7 @@ export const AddNewMemberInput = () => {
8783
/>
8884
<Button
8985
isPrimary
86+
isPill
9087
themeColor={globalTheme.palette.water[600]}
9188
type="submit"
9289
disabled={formProps.isSubmitting}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Modal, Button } from '@appquality/unguess-design-system';
2+
import { ReactComponent as LinkIcon } from 'src/assets/icons/link-stroke.svg';
3+
import { getColor } from '@zendeskgarden/react-theming';
4+
import styled from 'styled-components';
5+
import { useTranslation } from 'react-i18next';
6+
7+
const FooterWithBorder = styled(Modal.Footer)`
8+
border-top: 1px solid ${({ theme }) => getColor(theme.colors.neutralHue, 200)};
9+
padding: ${({ theme }) =>
10+
`${theme.space.base * 4}px ${theme.space.base * 8}px`};
11+
justify-content: start;
12+
`;
13+
14+
export const WorkspaceSettingsFooter = () => {
15+
const { t } = useTranslation();
16+
17+
return (
18+
<FooterWithBorder>
19+
<Button
20+
isBasic
21+
onClick={() => navigator.clipboard.writeText(window.location.href)}
22+
>
23+
<Button.StartIcon>
24+
<LinkIcon />
25+
</Button.StartIcon>
26+
{t('__WORKSPACE_SETTINGS_MODAL_CTA_COPY_LINK')}
27+
</Button>
28+
</FooterWithBorder>
29+
);
30+
};

src/common/components/navigation/header/settings/userItem.tsx

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { getInitials } from '../utils';
2525
const StyledEllipsis = styled(Ellipsis)``;
2626
const UserListItem = styled.div`
2727
display: flex;
28-
padding: ${({ theme }) => `${theme.space.xs} ${theme.space.sm}`};
28+
padding: ${({ theme }) => `${theme.space.xs} 0`};
2929
align-items: center;
3030
gap: ${({ theme }) => theme.space.sm};
3131
@@ -38,10 +38,6 @@ const UserListItem = styled.div`
3838
}
3939
`;
4040

41-
const StyledSM = styled(SM)`
42-
color: ${({ theme }) => theme.palette.grey[600]};
43-
`;
44-
4541
export const UserItem = ({
4642
user,
4743
}: {
@@ -65,66 +61,64 @@ export const UserItem = ({
6561
<div>
6662
<StyledEllipsis>
6763
{displayName}{' '}
68-
{isMe && (
69-
<StyledSM>
70-
{t('__WORKSPACE_SETTINGS_CURRENT_MEMBER_YOU_LABEL')}
71-
</StyledSM>
72-
)}
64+
{isMe && t('__WORKSPACE_SETTINGS_CURRENT_MEMBER_YOU_LABEL')}
7365
</StyledEllipsis>
7466
</div>
7567
<div className="actions">
76-
<Dropdown
77-
onStateChange={(options) =>
78-
Object.hasOwn(options, 'isOpen') && setRotated(options.isOpen)
79-
}
80-
>
81-
<Trigger>
82-
<Button isBasic aria-label="user management actions">
83-
{user.invitationPending ? (
84-
<Span hue={globalTheme.palette.orange[600]}>
85-
{t('__WORKSPACE_SETTINGS_MEMBER_INVITATION_PENDING_LABEL')}
86-
</Span>
87-
) : (
88-
t('__WORKSPACE_SETTINGS_MEMBER_ACTIONS_LABEL')
68+
{!isMe && (
69+
<Dropdown
70+
onStateChange={(options) =>
71+
Object.hasOwn(options, 'isOpen') && setRotated(options.isOpen)
72+
}
73+
>
74+
<Trigger>
75+
<Button isBasic aria-label="user management actions">
76+
{user.invitationPending ? (
77+
<Span hue={globalTheme.palette.orange[600]}>
78+
{t('__WORKSPACE_SETTINGS_MEMBER_INVITATION_PENDING_LABEL')}
79+
</Span>
80+
) : (
81+
t('__WORKSPACE_SETTINGS_MEMBER_ACTIONS_LABEL')
82+
)}
83+
<Button.EndIcon isRotated={rotated}>
84+
<ChevronIcon />
85+
</Button.EndIcon>
86+
</Button>
87+
</Trigger>
88+
<Menu placement="bottom-end">
89+
{user.invitationPending && (
90+
<Item
91+
value="invite"
92+
onClick={() =>
93+
addNewMember({
94+
wid: activeWorkspace.id.toString() || '0',
95+
body: {
96+
email: user.email,
97+
},
98+
}).unwrap()
99+
}
100+
>
101+
{t('__WORKSPACE_SETTINGS_MEMBER_RESEND_INVITE_ACTION')}
102+
</Item>
89103
)}
90-
<Button.EndIcon isRotated={rotated}>
91-
<ChevronIcon />
92-
</Button.EndIcon>
93-
</Button>
94-
</Trigger>
95-
<Menu placement="bottom-end">
96-
{user.invitationPending && (
97104
<Item
98-
value="invite"
105+
value="remove"
99106
onClick={() =>
100-
addNewMember({
107+
removeUser({
101108
wid: activeWorkspace.id.toString() || '0',
102109
body: {
103-
email: user.email,
110+
user_id: user.id,
104111
},
105112
}).unwrap()
106113
}
107114
>
108-
{t('__WORKSPACE_SETTINGS_MEMBER_RESEND_INVITE_ACTION')}
115+
<Span hue={globalTheme.colors.dangerHue}>
116+
{t('__WORKSPACE_SETTINGS_MEMBER_REMOVE_USER_ACTION')}
117+
</Span>
109118
</Item>
110-
)}
111-
<Item
112-
value="remove"
113-
onClick={() =>
114-
removeUser({
115-
wid: activeWorkspace.id.toString() || '0',
116-
body: {
117-
user_id: user.id,
118-
},
119-
}).unwrap()
120-
}
121-
>
122-
<Span hue={globalTheme.colors.dangerHue}>
123-
{t('__WORKSPACE_SETTINGS_MEMBER_REMOVE_USER_ACTION')}
124-
</Span>
125-
</Item>
126-
</Menu>
127-
</Dropdown>
119+
</Menu>
120+
</Dropdown>
121+
)}
128122
</div>
129123
</UserListItem>
130124
);

src/common/components/navigation/header/settings/workspaceSettings.tsx

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,21 @@
1-
import {
2-
Button,
3-
IconButton,
4-
Modal,
5-
XL,
6-
Grid,
7-
Avatar,
8-
} from '@appquality/unguess-design-system';
1+
import { Button, Modal, ModalClose } from '@appquality/unguess-design-system';
92
import { useAppSelector } from 'src/app/hooks';
103
import styled from 'styled-components';
114
import { ReactComponent as GearIcon } from 'src/assets/icons/gear-fill.svg';
125
import { useState } from 'react';
136
import { useTranslation } from 'react-i18next';
14-
import { theme as globalTheme } from 'src/app/theme';
15-
import { Divider } from 'src/common/components/divider';
167
import { useGetWorkspacesByWidUsersQuery } from 'src/features/api';
178
import { AddNewMemberInput } from './addNewMember';
18-
import { getInitials } from '../utils';
199
import { UserItem } from './userItem';
10+
import { WorkspaceSettingsFooter } from './modalFooter';
2011

21-
const FlexContainer = styled.div`
12+
const FlexContainer = styled.div<{ loading?: boolean }>`
2213
display: flex;
2314
flex-direction: column;
2415
padding-top: ${({ theme }) => theme.space.base * 2}px;
2516
margin-bottom: ${({ theme }) => theme.space.base * 6}px;
26-
`;
27-
28-
const CompanyHolder = styled(XL)`
29-
text-transform: uppercase;
30-
margin-top: ${({ theme }) => theme.space.base * 2}px;
31-
margin-bottom: ${({ theme }) => theme.space.base * 4}px;
32-
color: ${({ theme }) => theme.colors.primaryHue};
33-
align-self: center;
34-
`;
35-
36-
const UserListItem = styled.div`
37-
display: flex;
38-
padding: ${({ theme }) => `${theme.space.xs} ${theme.space.sm}`};
39-
align-items: center;
40-
gap: ${({ theme }) => theme.space.sm};
41-
42-
button {
43-
margin-left: auto;
44-
}
17+
min-height: 0;
18+
opacity: ${({ loading }) => (loading ? 0.5 : 1)};
4519
`;
4620

4721
export const WorkspaceSettings = () => {
@@ -61,32 +35,23 @@ export const WorkspaceSettings = () => {
6135
<Button.StartIcon>
6236
<GearIcon />
6337
</Button.StartIcon>
64-
Manage users
38+
{t('__WORKSPACE_SETTINGS_CTA_TEXT')}
6539
</Button>
6640
{isModalOpen && (
6741
<Modal onClose={() => setIsModalOpen(false)}>
68-
<Modal.Body style={{ overflow: 'hidden' }}>
69-
<FlexContainer>
70-
<CompanyHolder>{`${activeWorkspace?.company}'s Workspace`}</CompanyHolder>
71-
<Divider style={{ marginBottom: globalTheme.space.sm }} />
72-
<AddNewMemberInput />
73-
74-
<FlexContainer>
75-
<Grid
76-
style={{
77-
opacity: isFetching ? 0.7 : 1,
78-
height: '400px',
79-
overflowY: 'auto',
80-
overflowX: 'hidden',
81-
}}
82-
>
83-
{data?.items.map((user) => (
84-
<UserItem user={user} />
85-
))}
86-
</Grid>
87-
</FlexContainer>
42+
<Modal.Header>{t('__WORKSPACE_SETTINGS_MODAL_TITLE')}</Modal.Header>
43+
<Modal.Body>
44+
<AddNewMemberInput />
45+
</Modal.Body>
46+
<Modal.Body style={{ paddingTop: 0 }}>
47+
<FlexContainer loading={isLoading || isFetching}>
48+
{data?.items.map((user) => (
49+
<UserItem user={user} />
50+
))}
8851
</FlexContainer>
8952
</Modal.Body>
53+
<WorkspaceSettingsFooter />
54+
<ModalClose />
9055
</Modal>
9156
)}
9257
</>

src/locales/en/translation.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,11 +668,14 @@
668668
"__WORKSPACE_SETTINGS_ADD_MEMBER_EMAIL_PLACEHOLDER": "Email address",
669669
"__WORKSPACE_SETTINGS_ADD_MEMBER_INVALID_EMAIL_ERROR": "Invalid email address",
670670
"__WORKSPACE_SETTINGS_ADD_MEMBER_REQUIRED_EMAIL_ERROR": "Required field",
671+
"__WORKSPACE_SETTINGS_CTA_TEXT": "manage users",
671672
"__WORKSPACE_SETTINGS_CURRENT_MEMBER_YOU_LABEL": "(you)",
672673
"__WORKSPACE_SETTINGS_MEMBER_ACTIONS_LABEL": "member",
673674
"__WORKSPACE_SETTINGS_MEMBER_INVITATION_PENDING_LABEL": "invited",
674675
"__WORKSPACE_SETTINGS_MEMBER_REMOVE_USER_ACTION": "Remove",
675676
"__WORKSPACE_SETTINGS_MEMBER_RESEND_INVITE_ACTION": "Re-send invite",
677+
"__WORKSPACE_SETTINGS_MODAL_CTA_COPY_LINK": "Copy link to page",
678+
"__WORKSPACE_SETTINGS_MODAL_TITLE": "Manage users",
676679
"Devices ({{count}})_one": "Devices ({{count}})",
677680
"Devices ({{count}})_other": "Devices ({{count}})",
678681
"OS ({{count}})_one": "OS ({{count}})",

src/locales/it/translation.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,11 +668,14 @@
668668
"__WORKSPACE_SETTINGS_ADD_MEMBER_EMAIL_PLACEHOLDER": "Indirizzo email",
669669
"__WORKSPACE_SETTINGS_ADD_MEMBER_INVALID_EMAIL_ERROR": "Email non valida",
670670
"__WORKSPACE_SETTINGS_ADD_MEMBER_REQUIRED_EMAIL_ERROR": "Campo obbligatorio",
671+
"__WORKSPACE_SETTINGS_CTA_TEXT": "gestisci utenti",
671672
"__WORKSPACE_SETTINGS_CURRENT_MEMBER_YOU_LABEL": "(tu)",
672673
"__WORKSPACE_SETTINGS_MEMBER_ACTIONS_LABEL": "membro",
673674
"__WORKSPACE_SETTINGS_MEMBER_INVITATION_PENDING_LABEL": "invitato",
674675
"__WORKSPACE_SETTINGS_MEMBER_REMOVE_USER_ACTION": "Rimuovi",
675676
"__WORKSPACE_SETTINGS_MEMBER_RESEND_INVITE_ACTION": "Rimanda invito",
677+
"__WORKSPACE_SETTINGS_MODAL_CTA_COPY_LINK": "Copia il link alla pagina",
678+
"__WORKSPACE_SETTINGS_MODAL_TITLE": "Gestisci gli utenti",
676679
"Devices ({{count}})_one": "Dispositivi ({{count}})",
677680
"Devices ({{count}})_other": "Dispositivi ({{count}})",
678681
"OS ({{count}})_one": "OS ({{count}})",

0 commit comments

Comments
 (0)