2023-08-02 09:35:48 +00:00
|
|
|
import { useRouter } from "next/navigation";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { FormEvent } from "react";
|
|
|
|
import { useRef, useState } from "react";
|
2022-09-06 22:58:16 +00:00
|
|
|
import { useForm } from "react-hook-form";
|
|
|
|
|
2023-10-24 10:42:36 +00:00
|
|
|
import OrganizationMemberAvatar from "@calcom/features/ee/organizations/components/OrganizationMemberAvatar";
|
2022-09-06 22:58:16 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2023-03-03 23:20:13 +00:00
|
|
|
import { md } from "@calcom/lib/markdownIt";
|
2023-02-10 09:53:03 +00:00
|
|
|
import { telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry";
|
2023-01-27 23:14:58 +00:00
|
|
|
import turndown from "@calcom/lib/turndownService";
|
2022-09-06 22:58:16 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2023-10-24 10:42:36 +00:00
|
|
|
import type { Ensure } from "@calcom/types/utils";
|
2023-09-07 15:26:40 +00:00
|
|
|
import { Button, Editor, ImageUploader, Label, showToast } from "@calcom/ui";
|
2023-05-17 12:47:44 +00:00
|
|
|
import { ArrowRight } from "@calcom/ui/components/icon";
|
2022-09-06 22:58:16 +00:00
|
|
|
|
|
|
|
type FormData = {
|
|
|
|
bio: string;
|
|
|
|
};
|
|
|
|
|
feat: Organizations (#8993)
* Initial commit
* Adding feature flag
* feat: Orgs Schema Changing `scopedMembers` to `orgUsers` (#9209)
* Change scopedMembers to orgMembers
* Change to orgUsers
* Letting duplicate slugs for teams to support orgs
* Covering null on unique clauses
* Supporting having the orgId in the session cookie
* feat: organization event type filter (#9253)
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Missing changes to support orgs schema changes
* 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
* Making sure we let localhost still work
* Feedback
* Type check fixes
* feat: Organization branding in side menu (#9279)
* 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
* Org branding provider used in shell sidebar
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Using org avatar (temp)
* Not showing org logo if not set
* User onboarding with org branding (slug)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* feedback
* Feedback
* Org public profile
* Public profiles for team event types
* Added setup profile alert
* Using org avatar on subteams avatar
* Making sure we show the set up profile on org only
* Profile username availability rely on org hook
* Update apps/web/pages/team/[slug].tsx
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* Update apps/web/pages/team/[slug].tsx
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* feat: Organization support for event types page (#9449)
* 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
* Org branding provider used in shell sidebar
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Using org avatar (temp)
* Not showing org logo if not set
* User onboarding with org branding (slug)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* feedback
* Feedback
* Org public profile
* Public profiles for team event types
* Added setup profile alert
* Using org avatar on subteams avatar
* Processing orgs and children as profile options
* Reverting change not belonging to this PR
* Making sure we show the set up profile on org only
* Removing console.log
* Comparing memberships to choose the highest one
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* Type errors
* Refactor and type fixes
* Update orgDomains.ts
* Feedback
* Reverting
* NIT
* fix issue getting org slug from domain
* Improving orgDomains util
* Host comes with port
* Update useRouterQuery.ts
* Feedback
* Feedback
* Feedback
* Feedback: SSR for user event-types to have org context
* chore: Cache node_modules (#9492)
* Adding check for cache hit
* Adding a separate install step first
* Put the restore cache steps back
* Revert the uses type for restoring cache
* Added step to restore nm cache
* Removed the cache-hit check
* Comments and naming
* Removed extra install command
* Updated the name of the linting step to be more clear
* Removes the need for useEffect here
* Feedback
* Feedback
* Cookie domain needs a dot
* Type fix
* Update apps/web/public/static/locales/en/common.json
Co-authored-by: Omar López <zomars@me.com>
* Update packages/emails/src/templates/OrganizationAccountVerifyEmail.tsx
* Feedback
---------
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
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: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: Efraín Rochín <roae.85@gmail.com>
Co-authored-by: Keith Williams <keithwillcode@gmail.com>
2023-06-14 21:40:20 +00:00
|
|
|
const UserProfile = () => {
|
|
|
|
const [user] = trpc.viewer.me.useSuspenseQuery();
|
2022-09-06 22:58:16 +00:00
|
|
|
const { t } = useLocale();
|
2023-06-06 11:59:57 +00:00
|
|
|
const avatarRef = useRef<HTMLInputElement>(null);
|
2023-01-25 01:08:10 +00:00
|
|
|
const { setValue, handleSubmit, getValues } = useForm<FormData>({
|
|
|
|
defaultValues: { bio: user?.bio || "" },
|
|
|
|
});
|
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const { data: eventTypes } = trpc.viewer.eventTypes.list.useQuery();
|
2022-09-06 22:58:16 +00:00
|
|
|
const [imageSrc, setImageSrc] = useState<string>(user?.avatar || "");
|
|
|
|
const utils = trpc.useContext();
|
|
|
|
const router = useRouter();
|
2022-11-10 23:40:01 +00:00
|
|
|
const createEventType = trpc.viewer.eventTypes.create.useMutation();
|
2023-02-10 09:53:03 +00:00
|
|
|
const telemetry = useTelemetry();
|
2023-04-19 11:40:18 +00:00
|
|
|
const [firstRender, setFirstRender] = useState(true);
|
2022-09-07 01:34:33 +00:00
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const mutation = trpc.viewer.updateProfile.useMutation({
|
2022-09-07 03:24:12 +00:00
|
|
|
onSuccess: async (_data, context) => {
|
|
|
|
if (context.avatar) {
|
|
|
|
showToast(t("your_user_profile_updated_successfully"), "success");
|
2022-11-10 23:40:01 +00:00
|
|
|
await utils.viewer.me.refetch();
|
2022-09-07 03:24:12 +00:00
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
if (eventTypes?.length === 0) {
|
|
|
|
await Promise.all(
|
|
|
|
DEFAULT_EVENT_TYPES.map(async (event) => {
|
|
|
|
return createEventType.mutate(event);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
2022-09-07 01:34:33 +00:00
|
|
|
}
|
2022-09-06 22:58:16 +00:00
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
await utils.viewer.me.refetch();
|
2022-09-07 03:24:12 +00:00
|
|
|
router.push("/");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onError: () => {
|
|
|
|
showToast(t("problem_saving_user_profile"), "error");
|
|
|
|
},
|
2022-09-06 22:58:16 +00:00
|
|
|
});
|
2022-09-07 01:34:33 +00:00
|
|
|
const onSubmit = handleSubmit((data: { bio: string }) => {
|
2022-09-06 22:58:16 +00:00
|
|
|
const { bio } = data;
|
|
|
|
|
2023-02-10 09:53:03 +00:00
|
|
|
telemetry.event(telemetryEventTypes.onboardingFinished);
|
|
|
|
|
2022-09-06 22:58:16 +00:00
|
|
|
mutation.mutate({
|
|
|
|
bio,
|
|
|
|
completedOnboarding: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
async function updateProfileHandler(event: FormEvent<HTMLFormElement>) {
|
|
|
|
event.preventDefault();
|
2023-06-06 11:59:57 +00:00
|
|
|
const enteredAvatar = avatarRef.current?.value;
|
2022-09-06 22:58:16 +00:00
|
|
|
mutation.mutate({
|
|
|
|
avatar: enteredAvatar,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const DEFAULT_EVENT_TYPES = [
|
|
|
|
{
|
|
|
|
title: t("15min_meeting"),
|
|
|
|
slug: "15min",
|
|
|
|
length: 15,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: t("30min_meeting"),
|
|
|
|
slug: "30min",
|
|
|
|
length: 30,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: t("secret_meeting"),
|
|
|
|
slug: "secret",
|
|
|
|
length: 15,
|
|
|
|
hidden: true,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2023-10-24 10:42:36 +00:00
|
|
|
const organization =
|
|
|
|
user.organization && user.organization.id
|
|
|
|
? {
|
|
|
|
...(user.organization as Ensure<typeof user.organization, "id">),
|
|
|
|
slug: user.organization.slug || null,
|
|
|
|
requestedSlug: user.organization.metadata?.requestedSlug || null,
|
|
|
|
}
|
|
|
|
: null;
|
2022-09-06 22:58:16 +00:00
|
|
|
return (
|
2022-09-07 01:34:33 +00:00
|
|
|
<form onSubmit={onSubmit}>
|
2022-11-08 07:49:44 +00:00
|
|
|
<div className="flex flex-row items-center justify-start rtl:justify-end">
|
2023-09-07 15:26:40 +00:00
|
|
|
{user && (
|
2023-10-24 10:42:36 +00:00
|
|
|
<OrganizationMemberAvatar size="lg" user={user} previewSrc={imageSrc} organization={organization} />
|
2023-09-07 15:26:40 +00:00
|
|
|
)}
|
2022-09-06 22:58:16 +00:00
|
|
|
<input
|
|
|
|
ref={avatarRef}
|
|
|
|
type="hidden"
|
|
|
|
name="avatar"
|
|
|
|
id="avatar"
|
|
|
|
placeholder="URL"
|
2023-04-05 18:14:46 +00:00
|
|
|
className="border-default focus:ring-empthasis mt-1 block w-full rounded-sm border px-3 py-2 text-sm focus:border-gray-800 focus:outline-none"
|
2022-09-06 22:58:16 +00:00
|
|
|
defaultValue={imageSrc}
|
|
|
|
/>
|
|
|
|
<div className="flex items-center px-4">
|
|
|
|
<ImageUploader
|
|
|
|
target="avatar"
|
|
|
|
id="avatar-upload"
|
2022-11-08 07:49:44 +00:00
|
|
|
buttonMsg={t("add_profile_photo")}
|
2022-09-06 22:58:16 +00:00
|
|
|
handleAvatarChange={(newAvatar) => {
|
2023-06-06 11:59:57 +00:00
|
|
|
if (avatarRef.current) {
|
|
|
|
avatarRef.current.value = newAvatar;
|
|
|
|
}
|
2022-09-06 22:58:16 +00:00
|
|
|
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
|
|
|
|
window.HTMLInputElement.prototype,
|
|
|
|
"value"
|
|
|
|
)?.set;
|
|
|
|
nativeInputValueSetter?.call(avatarRef.current, newAvatar);
|
|
|
|
const ev2 = new Event("input", { bubbles: true });
|
2023-06-06 11:59:57 +00:00
|
|
|
avatarRef.current?.dispatchEvent(ev2);
|
2022-09-06 22:58:16 +00:00
|
|
|
updateProfileHandler(ev2 as unknown as FormEvent<HTMLFormElement>);
|
|
|
|
setImageSrc(newAvatar);
|
|
|
|
}}
|
|
|
|
imageSrc={imageSrc}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<fieldset className="mt-8">
|
2023-04-05 18:14:46 +00:00
|
|
|
<Label className="text-default mb-2 block text-sm font-medium">{t("about")}</Label>
|
2023-01-25 01:08:10 +00:00
|
|
|
<Editor
|
|
|
|
getText={() => md.render(getValues("bio") || user?.bio || "")}
|
2023-01-27 23:14:58 +00:00
|
|
|
setText={(value: string) => setValue("bio", turndown(value))}
|
2023-01-25 01:08:10 +00:00
|
|
|
excludedToolbarItems={["blockType"]}
|
2023-04-19 11:40:18 +00:00
|
|
|
firstRender={firstRender}
|
|
|
|
setFirstRender={setFirstRender}
|
2022-09-06 22:58:16 +00:00
|
|
|
/>
|
2023-04-05 18:14:46 +00:00
|
|
|
<p className="dark:text-inverted text-default mt-2 font-sans text-sm font-normal">
|
2022-09-06 22:58:16 +00:00
|
|
|
{t("few_sentences_about_yourself")}
|
|
|
|
</p>
|
|
|
|
</fieldset>
|
|
|
|
<Button
|
|
|
|
type="submit"
|
2023-04-05 18:14:46 +00:00
|
|
|
className="text-inverted mt-8 flex w-full flex-row justify-center rounded-md border border-black bg-black p-2 text-center text-sm">
|
2022-09-06 22:58:16 +00:00
|
|
|
{t("finish")}
|
2023-05-17 12:47:44 +00:00
|
|
|
<ArrowRight className="ml-2 h-4 w-4 self-center" aria-hidden="true" />
|
2022-09-06 22:58:16 +00:00
|
|
|
</Button>
|
|
|
|
</form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default UserProfile;
|