forked from umami-software/umami
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev' into dev
- Loading branch information
Showing
7 changed files
with
182 additions
and
19 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/app/(main)/settings/teams/[teamId]/members/TeamMemberEditButton.tsx
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,49 @@ | ||
import { useMessages, useModified } from 'components/hooks'; | ||
import { Button, Icon, Icons, Modal, ModalTrigger, Text, useToasts } from 'react-basics'; | ||
import TeamMemberEditForm from './TeamMemberEditForm'; | ||
|
||
export function TeamMemberEditButton({ | ||
teamId, | ||
userId, | ||
role, | ||
onSave, | ||
}: { | ||
teamId: string; | ||
userId: string; | ||
role: string; | ||
onSave?: () => void; | ||
}) { | ||
const { formatMessage, labels, messages } = useMessages(); | ||
const { showToast } = useToasts(); | ||
const { touch } = useModified(); | ||
|
||
const handleSave = () => { | ||
showToast({ message: formatMessage(messages.saved), variant: 'success' }); | ||
touch('teams:members'); | ||
onSave?.(); | ||
}; | ||
|
||
return ( | ||
<ModalTrigger> | ||
<Button variant="quiet"> | ||
<Icon> | ||
<Icons.Edit /> | ||
</Icon> | ||
<Text>{formatMessage(labels.edit)}</Text> | ||
</Button> | ||
<Modal title={formatMessage(labels.editMember)}> | ||
{(close: () => void) => ( | ||
<TeamMemberEditForm | ||
teamId={teamId} | ||
userId={userId} | ||
role={role} | ||
onSave={handleSave} | ||
onClose={close} | ||
/> | ||
)} | ||
</Modal> | ||
</ModalTrigger> | ||
); | ||
} | ||
|
||
export default TeamMemberEditButton; |
78 changes: 78 additions & 0 deletions
78
src/app/(main)/settings/teams/[teamId]/members/TeamMemberEditForm.tsx
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,78 @@ | ||
import { useApi, useMessages } from 'components/hooks'; | ||
import { ROLES } from 'lib/constants'; | ||
import { | ||
Button, | ||
Dropdown, | ||
Form, | ||
FormButtons, | ||
FormInput, | ||
FormRow, | ||
Item, | ||
SubmitButton, | ||
} from 'react-basics'; | ||
|
||
export function UserAddForm({ | ||
teamId, | ||
userId, | ||
role, | ||
onSave, | ||
onClose, | ||
}: { | ||
teamId: string; | ||
userId: string; | ||
role: string; | ||
onSave?: () => void; | ||
onClose?: () => void; | ||
}) { | ||
const { post, useMutation } = useApi(); | ||
const { mutate, error, isPending } = useMutation({ | ||
mutationFn: (data: any) => post(`/teams/${teamId}/users/${userId}`, data), | ||
}); | ||
const { formatMessage, labels } = useMessages(); | ||
|
||
const handleSubmit = async (data: any) => { | ||
mutate(data, { | ||
onSuccess: async () => { | ||
onSave(); | ||
onClose(); | ||
}, | ||
}); | ||
}; | ||
|
||
const renderValue = (value: string) => { | ||
if (value === ROLES.teamMember) { | ||
return formatMessage(labels.teamMember); | ||
} | ||
if (value === ROLES.teamViewOnly) { | ||
return formatMessage(labels.viewOnly); | ||
} | ||
}; | ||
|
||
return ( | ||
<Form onSubmit={handleSubmit} error={error} values={{ role }}> | ||
<FormRow label={formatMessage(labels.role)}> | ||
<FormInput name="role" rules={{ required: formatMessage(labels.required) }}> | ||
<Dropdown | ||
renderValue={renderValue} | ||
style={{ | ||
minWidth: '250px', | ||
}} | ||
> | ||
<Item key={ROLES.teamMember}>{formatMessage(labels.teamMember)}</Item> | ||
<Item key={ROLES.teamViewOnly}>{formatMessage(labels.viewOnly)}</Item> | ||
</Dropdown> | ||
</FormInput> | ||
</FormRow> | ||
<FormButtons flex> | ||
<SubmitButton variant="primary" disabled={false}> | ||
{formatMessage(labels.save)} | ||
</SubmitButton> | ||
<Button disabled={isPending} onClick={onClose}> | ||
{formatMessage(labels.cancel)} | ||
</Button> | ||
</FormButtons> | ||
</Form> | ||
); | ||
} | ||
|
||
export default UserAddForm; |
48 changes: 34 additions & 14 deletions
48
src/app/(main)/settings/teams/[teamId]/members/TeamMemberRemoveButton.tsx
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
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
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