-
Notifications
You must be signed in to change notification settings - Fork 13.6k
feat: organizations CRUD #29396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
feat: organizations CRUD #29396
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f7cf1cc
feat(organizations): add CRUD router and settings pages
regisstedile a36af84
feat(organizations): add member management (list, invite, remove, rol…
regisstedile 703ba44
feat(organizations): add invite accept/decline flow
regisstedile 9f545ce
feat(organizations): add API route, fix redirect conflict, and E2E tests
regisstedile ec9d601
style(organizations): fix import order in E2E test
regisstedile 5c4c176
fix(organizations): fix data consistency bugs found in code review
regisstedile aedf968
fix(teams): re-add tRPC endpoint and ENDPOINTS entry after organizati…
regisstedile b05375a
fix(organizations): address code review feedback
regisstedile d818e20
fix(organizations): point invite email link to /invites page
regisstedile 7c72a2b
fix(organizations): fix Button variant→color props (TS build error)
regisstedile fbcac7c
style(organizations): apply linter auto-fixes
regisstedile File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
154 changes: 154 additions & 0 deletions
154
apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/general/page.tsx
This file contains hidden or 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,154 @@ | ||
| "use client"; | ||
|
|
||
| import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader"; | ||
| import SectionBottomActions from "@calcom/features/settings/SectionBottomActions"; | ||
| import slugify from "@calcom/lib/slugify"; | ||
| import { useLocale } from "@calcom/lib/hooks/useLocale"; | ||
| import { trpc } from "@calcom/trpc/react"; | ||
| import { Button } from "@calcom/ui/components/button"; | ||
| import { Form, TextAreaField, TextField } from "@calcom/ui/components/form"; | ||
| import { showToast } from "@calcom/ui/components/toast"; | ||
| import { useEffect } from "react"; | ||
| import { useForm } from "react-hook-form"; | ||
|
|
||
| type OrganizationGeneralFormValues = { | ||
| name: string; | ||
| slug: string; | ||
| bio: string; | ||
| }; | ||
|
|
||
| export default function OrganizationGeneralPage() { | ||
| const { t } = useLocale(); | ||
| const utils = trpc.useUtils(); | ||
| const { data: organization, isLoading } = trpc.viewer.organizations.getCurrent.useQuery(); | ||
|
|
||
| const form = useForm<OrganizationGeneralFormValues>({ | ||
| defaultValues: { | ||
| name: "", | ||
| slug: "", | ||
| bio: "", | ||
| }, | ||
| }); | ||
|
|
||
| const { | ||
| formState: { isDirty, isSubmitting }, | ||
| reset, | ||
| watch, | ||
| setValue, | ||
| } = form; | ||
|
|
||
| useEffect(() => { | ||
| if (!organization) return; | ||
|
|
||
| reset({ | ||
| name: organization.name, | ||
| slug: organization.slug || "", | ||
| bio: organization.bio || "", | ||
| }); | ||
| }, [organization, reset]); | ||
|
|
||
| const createMutation = trpc.viewer.organizations.create.useMutation({ | ||
| onSuccess: async (createdOrganization) => { | ||
| await utils.viewer.organizations.getCurrent.invalidate(); | ||
| await utils.viewer.me.get.invalidate(); | ||
| reset({ | ||
| name: createdOrganization.name, | ||
| slug: createdOrganization.slug || "", | ||
| bio: createdOrganization.bio || "", | ||
| }); | ||
| showToast(t("settings_updated_successfully"), "success"); | ||
| }, | ||
| onError: (error) => { | ||
| showToast(error.message, "error"); | ||
| }, | ||
| }); | ||
|
|
||
| const updateMutation = trpc.viewer.organizations.update.useMutation({ | ||
| onSuccess: async (updatedOrganization) => { | ||
| await utils.viewer.organizations.getCurrent.invalidate(); | ||
| await utils.viewer.me.get.invalidate(); | ||
| reset({ | ||
| name: updatedOrganization.name, | ||
| slug: updatedOrganization.slug || "", | ||
| bio: updatedOrganization.bio || "", | ||
| }); | ||
| showToast(t("settings_updated_successfully"), "success"); | ||
| }, | ||
| onError: (error) => { | ||
| showToast(error.message, "error"); | ||
| }, | ||
| }); | ||
|
|
||
| const watchedName = watch("name"); | ||
| const canUpdate = !organization || organization.canUpdate; | ||
| const isSaving = createMutation.isPending || updateMutation.isPending || isSubmitting; | ||
| const isSubmitDisabled = isLoading || isSaving || !canUpdate || (!!organization && !isDirty); | ||
|
|
||
| return ( | ||
| <SettingsHeader | ||
| title={t("general")} | ||
| description={organization ? t("organization_general_description") : t("organizations_description")} | ||
| borderInShellHeader={true}> | ||
| <Form | ||
| form={form} | ||
| handleSubmit={async (values) => { | ||
| const payload = { | ||
| name: values.name, | ||
| slug: slugify(values.slug || values.name).toLowerCase(), | ||
| bio: values.bio || null, | ||
| }; | ||
|
|
||
| if (organization) { | ||
| await updateMutation.mutateAsync(payload); | ||
| } else { | ||
| await createMutation.mutateAsync(payload); | ||
| } | ||
| }}> | ||
| <div className="border-subtle space-y-6 border-x border-y-0 px-4 py-8 sm:px-6"> | ||
| <TextField | ||
| {...form.register("name", { required: true })} | ||
| data-testid="org-name-input" | ||
| label={t("organization_name")} | ||
| placeholder={t("organization_name")} | ||
| disabled={!canUpdate || isLoading} | ||
| required | ||
| /> | ||
|
|
||
| <TextField | ||
| data-testid="org-slug-input" | ||
| {...form.register("slug", { | ||
| required: true, | ||
| onChange: (event) => { | ||
| setValue("slug", slugify(event.target.value).toLowerCase(), { | ||
| shouldDirty: true, | ||
| shouldValidate: true, | ||
| }); | ||
| }, | ||
| })} | ||
| label={t("organization_url")} | ||
| placeholder={slugify(watchedName || "acme").toLowerCase()} | ||
| disabled={!canUpdate || isLoading} | ||
| required | ||
| /> | ||
|
|
||
| <TextAreaField | ||
| {...form.register("bio")} | ||
| label={t("organization_about_description")} | ||
| placeholder={t("organization_about_description")} | ||
| disabled={!canUpdate || isLoading} | ||
| rows={4} | ||
| /> | ||
|
|
||
| {!canUpdate && ( | ||
| <p className="text-sm text-subtle">{t("org_admin_only_settings")}</p> | ||
| )} | ||
| </div> | ||
| <SectionBottomActions align="end"> | ||
| <Button data-testid="org-submit-btn" type="submit" loading={isSaving} disabled={isSubmitDisabled}> | ||
| {organization ? t("save") : t("create_org")} | ||
| </Button> | ||
| </SectionBottomActions> | ||
| </Form> | ||
| </SettingsHeader> | ||
| ); | ||
| } | ||
88 changes: 88 additions & 0 deletions
88
apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/invites/page.tsx
This file contains hidden or 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,88 @@ | ||
| "use client"; | ||
|
|
||
| import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader"; | ||
| import { useLocale } from "@calcom/lib/hooks/useLocale"; | ||
| import { trpc } from "@calcom/trpc/react"; | ||
| import { Avatar } from "@calcom/ui/components/avatar"; | ||
| import { Button } from "@calcom/ui/components/button"; | ||
| import { showToast } from "@calcom/ui/components/toast"; | ||
| import { useRouter } from "next/navigation"; | ||
|
|
||
| export default function OrganizationInvitesPage() { | ||
| const { t } = useLocale(); | ||
| const router = useRouter(); | ||
| const utils = trpc.useUtils(); | ||
|
|
||
| const { data: invites, isLoading } = trpc.viewer.organizations.listPendingInvites.useQuery(); | ||
|
|
||
| const acceptMutation = trpc.viewer.organizations.acceptInvite.useMutation({ | ||
| onSuccess: async () => { | ||
| await utils.viewer.organizations.listPendingInvites.invalidate(); | ||
| await utils.viewer.me.get.invalidate(); | ||
| showToast(t("org_invite_joined"), "success"); | ||
| router.push("/settings/organizations/general"); | ||
| }, | ||
| onError: (err) => showToast(err.message, "error"), | ||
| }); | ||
|
|
||
| const declineMutation = trpc.viewer.organizations.declineInvite.useMutation({ | ||
| onSuccess: async () => { | ||
| await utils.viewer.organizations.listPendingInvites.invalidate(); | ||
| showToast(t("invite_declined"), "success"); | ||
| }, | ||
| onError: (err) => showToast(err.message, "error"), | ||
| }); | ||
|
|
||
| const pendingInvites = invites ?? []; | ||
| const isBusy = acceptMutation.isPending || declineMutation.isPending; | ||
|
|
||
| return ( | ||
| <SettingsHeader | ||
| title={t("org_invites")} | ||
| description={t("org_invites_description")} | ||
| borderInShellHeader={true}> | ||
| <div className="border-subtle border-x border-y-0 px-4 py-6 sm:px-6"> | ||
| {isLoading ? ( | ||
| <p className="text-subtle text-sm">{t("loading")}</p> | ||
| ) : pendingInvites.length === 0 ? ( | ||
| <p className="text-subtle text-sm">{t("no_pending_invites")}</p> | ||
| ) : ( | ||
| <ul className="divide-subtle divide-y"> | ||
| {pendingInvites.map(({ team }) => ( | ||
| <li key={team.id} data-testid={`invite-item-${team.id}`} className="flex items-center gap-3 py-4"> | ||
| <Avatar | ||
| alt={team.name} | ||
| imageSrc={team.logoUrl ?? undefined} | ||
| size="md" | ||
| fallback={team.name[0]?.toUpperCase()} | ||
| /> | ||
| <div className="min-w-0 flex-1"> | ||
| <p className="text-default text-sm font-semibold">{team.name}</p> | ||
| {team.slug && <p className="text-subtle text-xs">{team.slug}</p>} | ||
| </div> | ||
| <div className="flex shrink-0 gap-2"> | ||
| <Button | ||
| data-testid={`decline-invite-${team.id}`} | ||
| color="minimal" | ||
| size="sm" | ||
| disabled={isBusy} | ||
| onClick={() => declineMutation.mutate({ teamId: team.id })}> | ||
| {t("decline")} | ||
| </Button> | ||
| <Button | ||
| data-testid={`accept-invite-${team.id}`} | ||
| size="sm" | ||
| disabled={isBusy} | ||
| loading={acceptMutation.isPending} | ||
| onClick={() => acceptMutation.mutate({ teamId: team.id })}> | ||
| {t("accept")} | ||
| </Button> | ||
| </div> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| )} | ||
| </div> | ||
| </SettingsHeader> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.