2022-11-10 20:23:56 +00:00
|
|
|
import { useRouter } from "next/router";
|
2023-04-03 14:37:58 +00:00
|
|
|
import { useState } from "react";
|
2022-11-10 20:23:56 +00:00
|
|
|
import { Controller, useForm } from "react-hook-form";
|
2022-11-29 21:38:54 +00:00
|
|
|
import { z } from "zod";
|
2022-11-10 20:23:56 +00:00
|
|
|
|
feat: Org settings - profile,appearance, child teams, create new child (#9231)
* Initial commit
* Adding feature flag
* Desktop first banner, mobile pending
* Removing dead code and img
* AppInstallButtonBase
* WIP
* Adds Email verification template+translations for organizations (#9202)
* feat: Orgs Schema Changing `scopedMembers` to `orgUsers` (#9209)
* Change scopedMembers to orgMembers
* Change to orgUsers
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Session logic to show org label
* Step 2 done, avatar not working
* List orgs and list teams specific if orgs exist
* Conditionally show org - fix settings layout - add labels for all pages
* Profile Page + update
* Org specific team creation
* appearance page
* Ensure members cant of org cant update settings in UI
* Fix update handler imports
* hide billing on sub teams
* Update profile slug page
* Letting duplicate slugs for teams to support orgs
* Add slug coliisions for org
* Covering null on unique clauses
* Covering null on unique clauses
* Extract to utils
* Update settings to use subdomain path in team url , team + org
* Supporting having the orgId in the session cookie
* Onboarding admins step
* Last step to create teams
* Update handler comments
* Upgrade ORG banner - disabled team banner for child teams
* Handle publishing ORGS
* Fix licenese issue
* Update packages/trpc/server/routers/viewer/teams/create.handler.ts
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* A11ly
* Feedback
* Making an org avatar (temp)
* Add slug colission detection for user and team name
* Fix Import
* Remove update password func
* Fix module import over relative
* feat: organization event type filter (#9253)
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Missing changes to support orgs schema changes
* Remove app install button sa its in 9337
* Remove i18n key not being used
* feat: Onboarding process to create an organization (#9184)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* feedback
* Making sure we check requestedSlug now
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* feat: [CAL-1816] Organization subdomain support (#9345)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* Covering users and subteams, excluding non-org users
* Unpublished teams shows correctly
* Create subdomain in Vercel
* feedback
* Renaming Vercel env vars
* Vercel domain check before creation
* Supporting cal-staging.com
* Change to have vercel detect it
* vercel domain check data message error
* Remove check domain
* Making sure we check requestedSlug now
* Feedback and unneeded code
* Reverting unneeded changes
* Unneeded changes
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* Vercel subdomain creation in PROD only
* feat: organization settings general and members page (#9266)
* feat: organization settings general page
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* feat: add members page
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* chore: remove
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: use invalidate
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: delete mutation
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: remove organization id
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* chore
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: use zod schema
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
---------
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Type fixes
* Reverting changes
* Update UsernameTextfield.tsx
* More reverts
* Update next-auth-options.ts
* Update common.json
* Type fixes
* Include invite token for orgs
* Update org schema
* Make token settings optional as it isnt used in orgs yet
* Fix missing prop
---------
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
Co-authored-by: Leo Giovanetti <hello@leog.me>
Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
2023-06-15 17:27:39 +00:00
|
|
|
import { extractDomainFromWebsiteUrl } from "@calcom/ee/organizations/lib/utils";
|
2023-07-03 08:06:12 +00:00
|
|
|
import { useOrgBrandingValues } from "@calcom/features/ee/organizations/hooks";
|
2023-01-05 19:55:55 +00:00
|
|
|
import { getSafeRedirectUrl } from "@calcom/lib/getSafeRedirectUrl";
|
2022-11-10 20:23:56 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import slugify from "@calcom/lib/slugify";
|
2023-02-10 09:53:03 +00:00
|
|
|
import { telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry";
|
2022-11-10 20:23:56 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2023-07-03 08:06:12 +00:00
|
|
|
import { Avatar, Button, Form, ImageUploader, TextField, Alert, Label } from "@calcom/ui";
|
|
|
|
import { ArrowRight, Plus } from "@calcom/ui/components/icon";
|
2022-11-10 20:23:56 +00:00
|
|
|
|
2023-03-07 23:02:05 +00:00
|
|
|
import type { NewTeamFormValues } from "../lib/types";
|
2022-11-10 20:23:56 +00:00
|
|
|
|
2022-12-19 14:38:33 +00:00
|
|
|
const querySchema = z.object({
|
2023-06-23 20:01:54 +00:00
|
|
|
returnTo: z.string().optional(),
|
|
|
|
slug: z.string().optional(),
|
2022-12-19 14:38:33 +00:00
|
|
|
});
|
2022-11-29 21:38:54 +00:00
|
|
|
|
2022-11-10 20:23:56 +00:00
|
|
|
export const CreateANewTeamForm = () => {
|
|
|
|
const { t } = useLocale();
|
|
|
|
const router = useRouter();
|
2023-02-10 09:53:03 +00:00
|
|
|
const telemetry = useTelemetry();
|
2023-06-23 20:01:54 +00:00
|
|
|
const parsedQuery = querySchema.safeParse(router.query);
|
2023-04-03 14:37:58 +00:00
|
|
|
const [serverErrorMessage, setServerErrorMessage] = useState<string | null>(null);
|
2023-07-03 08:06:12 +00:00
|
|
|
const orgBranding = useOrgBrandingValues();
|
2022-12-19 14:38:33 +00:00
|
|
|
|
2023-01-05 19:55:55 +00:00
|
|
|
const returnToParam =
|
2023-06-23 20:01:54 +00:00
|
|
|
(parsedQuery.success ? getSafeRedirectUrl(parsedQuery.data.returnTo) : "/settings/teams") ||
|
2023-01-05 19:55:55 +00:00
|
|
|
"/settings/teams";
|
2022-11-29 21:38:54 +00:00
|
|
|
|
2023-06-23 20:01:54 +00:00
|
|
|
const newTeamFormMethods = useForm<NewTeamFormValues>({
|
|
|
|
defaultValues: {
|
|
|
|
slug: parsedQuery.success ? parsedQuery.data.slug : "",
|
|
|
|
},
|
|
|
|
});
|
2022-11-10 20:23:56 +00:00
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const createTeamMutation = trpc.viewer.teams.create.useMutation({
|
2022-11-10 20:23:56 +00:00
|
|
|
onSuccess: (data) => {
|
2023-02-10 09:53:03 +00:00
|
|
|
telemetry.event(telemetryEventTypes.team_created);
|
2022-11-10 20:23:56 +00:00
|
|
|
router.push(`/settings/teams/${data.id}/onboard-members`);
|
|
|
|
},
|
2023-04-03 14:37:58 +00:00
|
|
|
onError: (err) => {
|
|
|
|
if (err.message === "team_url_taken") {
|
2023-06-30 04:06:01 +00:00
|
|
|
newTeamFormMethods.setError("slug", { type: "custom", message: t("url_taken") });
|
2023-04-03 14:37:58 +00:00
|
|
|
} else {
|
|
|
|
setServerErrorMessage(err.message);
|
|
|
|
}
|
|
|
|
},
|
2022-11-10 20:23:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-11-12 13:31:11 +00:00
|
|
|
<Form
|
|
|
|
form={newTeamFormMethods}
|
|
|
|
handleSubmit={(v) => {
|
2023-04-03 14:37:58 +00:00
|
|
|
if (!createTeamMutation.isLoading) {
|
|
|
|
setServerErrorMessage(null);
|
|
|
|
createTeamMutation.mutate(v);
|
|
|
|
}
|
2022-11-12 13:31:11 +00:00
|
|
|
}}>
|
2022-11-10 20:23:56 +00:00
|
|
|
<div className="mb-8">
|
2023-04-03 14:37:58 +00:00
|
|
|
{serverErrorMessage && (
|
|
|
|
<div className="mb-4">
|
|
|
|
<Alert severity="error" message={serverErrorMessage} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
2022-11-10 20:23:56 +00:00
|
|
|
<Controller
|
|
|
|
name="name"
|
|
|
|
control={newTeamFormMethods.control}
|
|
|
|
defaultValue=""
|
|
|
|
rules={{
|
|
|
|
required: t("must_enter_team_name"),
|
|
|
|
}}
|
|
|
|
render={({ field: { value } }) => (
|
|
|
|
<>
|
|
|
|
<TextField
|
|
|
|
className="mt-2"
|
2023-04-05 18:14:46 +00:00
|
|
|
placeholder="Acme Inc."
|
2022-11-10 20:23:56 +00:00
|
|
|
name="name"
|
|
|
|
label={t("team_name")}
|
2022-11-30 20:51:44 +00:00
|
|
|
defaultValue={value}
|
2022-11-10 20:23:56 +00:00
|
|
|
onChange={(e) => {
|
|
|
|
newTeamFormMethods.setValue("name", e?.target.value);
|
|
|
|
if (newTeamFormMethods.formState.touchedFields["slug"] === undefined) {
|
|
|
|
newTeamFormMethods.setValue("slug", slugify(e?.target.value));
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
autoComplete="off"
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="mb-8">
|
|
|
|
<Controller
|
|
|
|
name="slug"
|
|
|
|
control={newTeamFormMethods.control}
|
2023-04-03 14:37:58 +00:00
|
|
|
rules={{ required: t("team_url_required") }}
|
2022-11-10 20:23:56 +00:00
|
|
|
render={({ field: { value } }) => (
|
|
|
|
<TextField
|
|
|
|
className="mt-2"
|
|
|
|
name="slug"
|
2023-04-05 18:14:46 +00:00
|
|
|
placeholder="acme"
|
2022-11-10 20:23:56 +00:00
|
|
|
label={t("team_url")}
|
2023-07-03 08:06:12 +00:00
|
|
|
addOnLeading={`${
|
|
|
|
orgBranding?.fullDomain.replace("https://", "").replace("http://", "") ??
|
|
|
|
`${extractDomainFromWebsiteUrl}/team/`
|
|
|
|
}`}
|
2022-11-30 20:51:44 +00:00
|
|
|
defaultValue={value}
|
2022-11-10 20:23:56 +00:00
|
|
|
onChange={(e) => {
|
|
|
|
newTeamFormMethods.setValue("slug", slugify(e?.target.value), {
|
|
|
|
shouldTouch: true,
|
|
|
|
});
|
2023-04-03 14:37:58 +00:00
|
|
|
newTeamFormMethods.clearErrors("slug");
|
2022-11-10 20:23:56 +00:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="mb-8">
|
|
|
|
<Controller
|
|
|
|
control={newTeamFormMethods.control}
|
|
|
|
name="logo"
|
|
|
|
render={({ field: { value } }) => (
|
2023-07-03 08:06:12 +00:00
|
|
|
<>
|
|
|
|
<Label>{t("team_logo")}</Label>
|
|
|
|
<div className="flex items-center">
|
|
|
|
<Avatar
|
|
|
|
alt=""
|
2022-11-10 20:23:56 +00:00
|
|
|
imageSrc={value}
|
2023-07-03 08:06:12 +00:00
|
|
|
fallback={<Plus className="text-subtle h-6 w-6" />}
|
|
|
|
size="lg"
|
2022-11-10 20:23:56 +00:00
|
|
|
/>
|
2023-07-03 08:06:12 +00:00
|
|
|
<div className="ms-4">
|
|
|
|
<ImageUploader
|
|
|
|
target="avatar"
|
|
|
|
id="avatar-upload"
|
|
|
|
buttonMsg={t("update")}
|
|
|
|
handleAvatarChange={(newAvatar: string) => {
|
|
|
|
newTeamFormMethods.setValue("logo", newAvatar);
|
|
|
|
createTeamMutation.reset();
|
|
|
|
}}
|
|
|
|
imageSrc={value}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-11-10 20:23:56 +00:00
|
|
|
</div>
|
2023-07-03 08:06:12 +00:00
|
|
|
</>
|
2022-11-10 20:23:56 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2023-01-04 07:38:45 +00:00
|
|
|
<div className="flex space-x-2 rtl:space-x-reverse">
|
2022-11-12 13:31:11 +00:00
|
|
|
<Button
|
|
|
|
disabled={createTeamMutation.isLoading}
|
|
|
|
color="secondary"
|
2022-11-29 21:38:54 +00:00
|
|
|
href={returnToParam}
|
2022-11-12 13:31:11 +00:00
|
|
|
className="w-full justify-center">
|
2022-11-10 20:23:56 +00:00
|
|
|
{t("cancel")}
|
|
|
|
</Button>
|
2022-11-12 13:31:11 +00:00
|
|
|
<Button
|
2023-04-03 14:37:58 +00:00
|
|
|
disabled={newTeamFormMethods.formState.isSubmitting || createTeamMutation.isLoading}
|
2022-11-12 13:31:11 +00:00
|
|
|
color="primary"
|
2023-04-12 15:26:31 +00:00
|
|
|
EndIcon={ArrowRight}
|
2023-03-07 23:02:05 +00:00
|
|
|
type="submit"
|
2022-11-12 13:31:11 +00:00
|
|
|
className="w-full justify-center">
|
2022-11-10 20:23:56 +00:00
|
|
|
{t("continue")}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</Form>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|