-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(permissions): manage permissions from a single location (#3730)
Co-authored-by: Zach Aysan <[email protected]>
- Loading branch information
Showing
33 changed files
with
1,445 additions
and
1,440 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
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { FC, ReactNode, useEffect, useState } from 'react' | ||
import OrganisationStore from 'common/stores/organisation-store' | ||
import AccountStore from 'common/stores/account-store' | ||
import AppActions from 'common/dispatcher/app-actions' | ||
import { | ||
Invite, | ||
InviteLink, | ||
Project, | ||
SubscriptionMeta, | ||
User, | ||
UserGroupSummary, | ||
} from 'common/types/responses' | ||
import { useGetGroupsQuery } from 'common/services/useGroup' | ||
|
||
type OrganisationProviderType = { | ||
onRemoveProject?: () => void | ||
onSave?: (data: { environmentId: number; projectId: number }) => void | ||
id?: number | ||
children: (props: { | ||
createProject: typeof AppActions.createProject | ||
invalidateInviteLink: typeof AppActions.invalidateInviteLink | ||
inviteLinks: InviteLink[] | null | ||
invites: Invite[] | null | ||
isLoading: boolean | ||
isSaving: boolean | ||
name: string | ||
project: Project | null | ||
groups: UserGroupSummary[] | null | ||
projects: Project[] | null | ||
subscriptionMeta: SubscriptionMeta | null | ||
users: User[] | null | ||
}) => ReactNode | ||
} | ||
|
||
const OrganisationProvider: FC<OrganisationProviderType> = ({ | ||
children, | ||
id, | ||
onRemoveProject, | ||
onSave, | ||
}) => { | ||
const [_, setUpdate] = useState(Date.now()) | ||
const { data: groups } = useGetGroupsQuery( | ||
{ orgId: id!, page: 1 }, | ||
{ skip: !id }, | ||
) | ||
useEffect(() => { | ||
const _onRemoveProject = () => onRemoveProject?.() | ||
OrganisationStore.on('removed', _onRemoveProject) | ||
return () => { | ||
OrganisationStore.off('removed', _onRemoveProject) | ||
} | ||
//eslint-disable-next-line | ||
}, []) | ||
|
||
useEffect(() => { | ||
const _onSave = () => onSave?.(OrganisationStore.savedId) | ||
OrganisationStore.on('saved', _onSave) | ||
return () => { | ||
OrganisationStore.off('saved', _onSave) | ||
} | ||
//eslint-disable-next-line | ||
}, []) | ||
|
||
useEffect(() => { | ||
const onChange = () => { | ||
setUpdate(Date.now()) | ||
} | ||
OrganisationStore.on('change', onChange) | ||
return () => { | ||
OrganisationStore.off('change', onChange) | ||
} | ||
//eslint-disable-next-line | ||
}, []) | ||
|
||
return ( | ||
<> | ||
{children({ | ||
createProject: AppActions.createProject, | ||
groups: groups?.results || [], | ||
invalidateInviteLink: AppActions.invalidateInviteLink, | ||
inviteLinks: OrganisationStore.getInviteLinks(), | ||
invites: OrganisationStore.getInvites(), | ||
isLoading: OrganisationStore.isLoading, | ||
isSaving: OrganisationStore.isSaving, | ||
name: AccountStore.getOrganisation()?.name || '', | ||
project: OrganisationStore.getProject(id), | ||
projects: OrganisationStore.getProjects(), | ||
subscriptionMeta: OrganisationStore.getSubscriptionMeta(), | ||
users: OrganisationStore.getUsers(), | ||
})} | ||
</> | ||
) | ||
} | ||
|
||
export default OrganisationProvider |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.