mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* feat: add @coss/ui/icons package and migrate static icon usages
Create a new icon system in @coss/ui/icons that wraps lucide-react icons
with controlled props (size and className only). Migrate 44 component
files from <Icon name="xxx" /> to <XxxIcon /> pattern.
This is Phase 1 of the icon migration, covering only static icon names.
Dynamic icon usages (e.g., name={variable}) are skipped for now.
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate more static icons to @coss/ui/icons (batch 2)
Migrated 18 files from <Icon name="xxx" /> to <XxxIcon /> pattern:
- Event meta, insights, shell, user table bulk actions
- Webhooks, blocklist, form-builder, form components
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate more static icons to @coss/ui/icons (batch 3)
Migrated 7 files:
- CancelBooking, AddGuestsDialog, ChargeCardDialog
- ReassignDialog, RescheduleDialog
- Categories, Slider
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate more static icons to @coss/ui/icons (batch 4)
Migrated 6 files:
- Organizations: AboutOrganizationForm, PaymentStatusView, profile
- Workflows: CallDetailsSheet, SkeletonLoaderList, TimeTimeUnitInput
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate more static icons to @coss/ui/icons (batch 5)
Migrated 4 files:
- TwoFactorModalHeader
- App setups: alby, make, btcpayserver
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate static icons to @coss/ui/icons (batch 6)
- confirmDialog.tsx: clock icon
- ics-feedcalendar/Setup.tsx: trash, plus icons
- hitpay/Setup.tsx: info icon
- paypal/Setup.tsx: circle-alert icons
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate static icons to @coss/ui/icons (batch 7)
- webhook-edit-view.tsx: external-link icon
- webhook-new-view.tsx: external-link icon
- UserDropdown.tsx: chevron-down, user, settings, moon, map, circle-help, download, blocks, log-out icons
- TopNav.tsx: settings icon
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate static icons to @coss/ui/icons (batch 8)
- EmailInviteForm.tsx: x icon
- InviteOptions.tsx: mail, upload, link icons
- SkeletonLoader.tsx: search, clock, user icons
- Embed.tsx: sun, arrow-left icons
- CalendarSwitch.tsx: arrow-left, rotate-cw icons
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate static icons to @coss/ui/icons (batch 9)
- apps-view.tsx: search icon
- categories-view.tsx: arrow-left, arrow-right icons
- DatePicker.tsx: calendar icon
- EditLocationDialog.tsx: map-pin icon
- AppPage.tsx: circle-alert, book-open, external-link, mail, file, shield, flag icons
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate static icons to @coss/ui/icons (batch 10)
- LicenseSelection.tsx: loader, check icons
- AppConnectionItem.tsx: circle-alert, arrow-right icons
- oauth-client-form/index.tsx: info icons (x2)
- auth/error/page.tsx: x icon
- troubleshoot/layout.tsx: loader icon
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate static icons to @coss/ui/icons (batch 11)
- UpgradeTipWrapper.tsx: users, refresh-ccw, user-plus icons
- PbacOptInModal.tsx: shield-check, lock, users, shield icons
- AdvancedPermissionGroup.tsx: chevron-right, info icons
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate static icons to @coss/ui/icons (batch 12)
- AdminAppsList.tsx: pencil icon
- AvailableTimes.tsx: calendar-x-2 icon
- BookingDetailsSheet.tsx: external-link (x2), repeat icons
- BookingCalendarContainer.tsx: chevron-left, chevron-right icons
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate static icons to @coss/ui/icons (batch 13)
- videos-single-view.tsx: chevron-right icon
- TroubleshooterSidebar.tsx: arrow-left icon
- RuleBuilder.tsx: filter icon
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate static icons to @coss/ui/icons (batch 14)
- FieldMappingBuilder.tsx: arrow-right, link icons
- IntegrationAttributeSyncCard.tsx: key icon
- onboarding-view.tsx: loader icon
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate static icons to @coss/ui/icons (batch 15)
- team-profile-view.tsx: copy icon
- DateRangeFilter.tsx: check icon
- ColumnVisibilityButton.tsx: check icon
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate static Icon to @coss/ui/icons (batch 16)
- EventWorkflowsTab.tsx: lock
- event-types-listing-view.tsx: search
- onboarding-migrate-members-browser-view.tsx: arrow-left, arrow-right, rotate-cw, lock, ellipsis-vertical, check, user-plus
- onboarding-migrate-teams-browser-view.tsx: arrow-left, arrow-right, rotate-cw, lock, ellipsis-vertical, check, arrow-right, users
- EventAvailabilityTab.tsx: globe, user
- onboarding-teams-browser-view.tsx: arrow-left, arrow-right, rotate-cw, lock, ellipsis-vertical, check, arrow-right, users
- FormBuilder.tsx: mail, phone, arrow-up, arrow-down
- AIEventController.tsx: info
- EventTeamAssignmentTab.tsx: x
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate static Icon to @coss/ui/icons (batch 17)
- EventAdvancedTab.tsx: pencil, info
- HostLocations.tsx: triangle-alert, loader
- EventTypeLayout.tsx: loader
- Locations.tsx: x, corner-down-right, check
- EditWeightsForAllTeamMembers.tsx: upload, search, info, chevron-down
- WorkflowPage.tsx: pencil
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate static Icon to @coss/ui/icons (batch 18)
- TestPhoneCallDialog.tsx: phone
- WorkflowListPage.tsx: link
- UsersTable.tsx: building, lock
- TeamList.tsx: building, paintbrush, chart-line, user-plus, users, pencil
- bookings-single-view.tsx: chevron-left, check, calendar, x, external-link
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate static Icon to @coss/ui/icons (batch 19)
- TeamsListing.tsx: users, refresh-ccw, user-plus, mail, video, eye-off, info
- ConnectionInfo.tsx: clipboard
- IntercomContactForm.tsx: message-circle, loader, send
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix: migrate static Icon to @coss/ui/icons in teams components
- EventTypesList.tsx: check → CheckIcon
- MemberInvitationModal.tsx: user, users, building → UserIcon, UsersIcon, BuildingIcon
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix: migrate static Icon to @coss/ui/icons in workflow components
- ImportNumberDialog.tsx: info → InfoIcon
- VoiceSelector.tsx: user → UserIcon
- IncomingCallsTab.tsx: info, phone-incoming → InfoIcon, PhoneIncomingIcon
- PhoneNumberTab.tsx: loader, phone → LoaderIcon, PhoneIcon
- VoiceSelectionDialog.tsx: pause, play, user → PauseIcon, PlayIcon, UserIcon
- WebCallDialog.tsx: loader, phone, phone-off, triangle-alert, trash, message-circle → new icons (kept Icon import for dynamic mic icon)
- WorkflowDetailsPage.tsx: zap, arrow-right → ZapIcon, ArrowRightIcon
- AddActionDialog.tsx: info → InfoIcon
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix: migrate static Icon to @coss/ui/icons in WorkflowStepContainer
- info → InfoIcon (2 instances)
- phone → PhoneIcon (2 instances)
- circle-help → CircleHelpIcon
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix: migrate static Icon to @coss/ui/icons in data-table and org components
- attributes-list-view.tsx: tags → TagsIcon
- AddFilterButton.tsx: plus, eye-off → PlusIcon, EyeOffIcon
- BaseSelectFilterOptions.tsx: check → CheckIcon
- DataTable.tsx: arrow-up, arrow-down, check, chevrons-up-down, eye-off → new icons
- booking-dry-run-success-view.tsx: check → CheckIcon
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix: migrate static Icon to @coss/ui/icons in username and routing components
- UsernameTextfield.tsx: check → CheckIcon
- PremiumTextfield.tsx: check, external-link → CheckIcon, ExternalLinkIcon (kept Icon for star with fill prop)
- Header.tsx (routing-forms): pencil, menu, waypoints → PencilIcon, MenuIcon, WaypointsIcon
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate Icon to component icons in routing-forms pages
Batch 25: Migrate static Icon usages to @coss/ui/icons components.
Files changed:
- Forms.tsx: file-text, shuffle, chart-bar, circle-check, mail, download → FileTextIcon, ShuffleIcon, ChartBarIcon, CircleCheckIcon, MailIcon, DownloadIcon
- FormEdit.tsx: chevron-down, menu → ChevronDownIcon, MenuIcon
- IncompleteBooking.tsx: globe → GlobeIcon
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate Icon to component icons in UI package
Batch 26: Migrate static Icon usages to @coss/ui/icons components.
Files changed:
- ProgressToast.tsx: file-down, x → FileDownIcon, XIcon
- showToast.tsx: check, info, x → CheckIcon, InfoIcon, XIcon
- InfoBadge.tsx: info → InfoIcon
- MeetingTimeInTimezones.tsx: globe → GlobeIcon
- InputError.tsx: info → InfoIcon
- ConfirmationDialogContent.tsx: circle-alert, check → CircleAlertIcon, CheckIcon
- CalendarSwitch.tsx: arrow-left, rotate-cw → ArrowLeftIcon, RotateCwIcon
- ArrowButton.tsx: arrow-up, arrow-down → ArrowUpIcon, ArrowDownIcon
- FileUploader.tsx: upload → UploadIcon (kept Icon for dynamic)
- Checkbox.tsx: check → CheckIcon
- EditableHeading.tsx: pencil → PencilIcon
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate Icon to component icons in UI and app-store packages
Batch 27: Migrate static Icon usages to @coss/ui/icons components.
Files changed:
- MultiEmail.tsx: x → XIcon (converted width to size)
- AppListCard.tsx: circle-alert → CircleAlertIcon
- SplitButton.tsx: chevron-down → ChevronDownIcon (kept Icon for dynamic)
- Calendar.tsx: chevron-left, chevron-right → ChevronLeftIcon, ChevronRightIcon
- AppDependencyComponent.tsx: check, circle-x, arrow-right → CheckIcon, CircleXIcon, ArrowRightIcon
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate Icon to component icons in form input components
Batch 28: Migrate static Icon usages to @coss/ui/icons components.
Files changed:
- TextField.tsx: info → InfoIcon (kept Icon for x with onClick)
- Input.tsx: eye, eye-off, search → EyeIcon, EyeOffIcon, SearchIcon
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix: use @coss/ui/src/icons in packages with legacy moduleResolution
Packages like packages/ui and packages/app-store use a legacy moduleResolution
setting that doesn't support subpath exports. This changes the import path from
@coss/ui/icons to @coss/ui/src/icons for these packages.
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate Icon to component icons in UI form and editor components
Migrates static Icon usages:
- MultiOptionInput: x (2x), arrow-up, arrow-down
- components (select): check
- AddVariablesDropdown: chevron-down (3x)
- ToolbarPlugin: chevron-down
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: migrate Icon to component icons in settings and platform atoms
Migrates static Icon usages:
- SettingsLayoutAppDirClient: chevron-down (2x), chevron-right (2x), arrow-left
- platform/atoms dialog: x
- platform/atoms toast: x
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix: resolve @coss/ui/icons module resolution for legacy moduleResolution
Add typesVersions to @coss/ui package.json to help TypeScript resolve
subpath exports even with legacy moduleResolution: "node" setting.
Change imports from @coss/ui/src/icons to @coss/ui/icons to avoid
double-src path issue when Next.js applies import maps.
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix: localize 'Select field type' fallback label in FormEdit
Address Cubic AI review feedback (confidence 9/10) by using t() for
the hardcoded 'Select field type' string to ensure proper i18n support.
Co-Authored-By: unknown <>
* fix: add typesVersions wildcards for @coss/ui subpath imports
Add lib/*, components/*, and hooks/* to typesVersions to support
legacy moduleResolution with all package subpath patterns.
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix: resolve missing Icon references in settings and workflows
- Add Icon import for dynamic icon usages in SettingsLayoutAppDirClient
- Replace static Icon usages with component icons (InfoIcon, PhoneIcon)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix: resolve icon component type errors
- Add onClick prop support to IconProps
- Fix size prop type (use number instead of string)
- Rename local MailOpenIcon to MailOpenIconWrapper to avoid shadowing
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix: add data-testid to icon components for test compatibility
- Add testId parameter to createIcon function
- Auto-generate data-testid for all icons (e.g., "check-icon", "search-icon")
- Remove outdated mock for @calcom/ui/components/icon in tests
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* Update package.json
* Update package.json
* fix: migrate Icon to CalendarDaysIcon in videos-single-view.tsx
Co-Authored-By: unknown <>
---------
Co-authored-by: Claude Opus 4.5 <[email protected]>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
496 lines
16 KiB
TypeScript
496 lines
16 KiB
TypeScript
"use client";
|
|
|
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
import { useSession } from "next-auth/react";
|
|
import Link from "next/link";
|
|
import { useRouter } from "next/navigation";
|
|
import { useEffect, useLayoutEffect, useState } from "react";
|
|
import { Controller, useForm } from "react-hook-form";
|
|
import { z } from "zod";
|
|
|
|
import { checkAdminOrOwner } from "@calcom/features/auth/lib/checkAdminOrOwner";
|
|
import { Dialog } from "@calcom/features/components/controlled-dialog";
|
|
import { getTeamUrlSync } from "@calcom/features/ee/organizations/lib/getTeamUrlSync";
|
|
import { trackFormbricksAction } from "@calcom/web/modules/formbricks/lib/trackFormbricksAction";
|
|
import SectionBottomActions from "@calcom/features/settings/SectionBottomActions";
|
|
import { IS_TEAM_BILLING_ENABLED, WEBAPP_URL } from "@calcom/lib/constants";
|
|
import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { useParamsWithFallback } from "@calcom/lib/hooks/useParamsWithFallback";
|
|
import { md } from "@calcom/lib/markdownIt";
|
|
import { markdownToSafeHTML } from "@calcom/lib/markdownToSafeHTML";
|
|
import objectKeys from "@calcom/lib/objectKeys";
|
|
import slugify from "@calcom/lib/slugify";
|
|
import turndown from "@calcom/lib/turndownService";
|
|
import type { Prisma } from "@calcom/prisma/client";
|
|
import type { RouterOutputs } from "@calcom/trpc/react";
|
|
import { trpc } from "@calcom/trpc/react";
|
|
import { Avatar } from "@calcom/ui/components/avatar";
|
|
import { Button, LinkIconButton } from "@calcom/ui/components/button";
|
|
import { DialogTrigger, ConfirmationDialogContent } from "@calcom/ui/components/dialog";
|
|
import { Editor } from "@calcom/ui/components/editor";
|
|
import { Form } from "@calcom/ui/components/form";
|
|
import { Label } from "@calcom/ui/components/form";
|
|
import { TextField } from "@calcom/ui/components/form";
|
|
import { ImageUploader } from "@calcom/ui/components/image-uploader";
|
|
import { CopyIcon } from "@coss/ui/icons";
|
|
import {
|
|
SkeletonButton,
|
|
SkeletonContainer,
|
|
SkeletonText,
|
|
SkeletonAvatar,
|
|
} from "@calcom/ui/components/skeleton";
|
|
import { showToast } from "@calcom/ui/components/toast";
|
|
import { Tooltip } from "@calcom/ui/components/tooltip";
|
|
import { revalidateTeamDataCache } from "@calcom/web/app/(booking-page-wrapper)/team/[slug]/[type]/actions";
|
|
import { revalidateEventTypesList } from "@calcom/web/app/(use-page-wrapper)/(main-nav)/event-types/actions";
|
|
import { revalidateTeamsList } from "@calcom/web/app/(use-page-wrapper)/(main-nav)/teams/actions";
|
|
|
|
const regex = new RegExp("^[a-zA-Z0-9-]*$");
|
|
|
|
const SkeletonLoader = () => {
|
|
return (
|
|
<SkeletonContainer>
|
|
<div className="border-subtle stack-y-6 rounded-b-xl border border-t-0 px-4 py-8">
|
|
<div className="flex items-center">
|
|
<SkeletonAvatar className="me-4 mt-0 h-16 w-16 px-4" />
|
|
<SkeletonButton className="h-6 w-32 rounded-md p-5" />
|
|
</div>
|
|
<SkeletonText className="h-8 w-full" />
|
|
<SkeletonText className="h-8 w-full" />
|
|
<SkeletonText className="h-8 w-full" />
|
|
|
|
<SkeletonButton className="mr-6 h-8 w-20 rounded-md p-5" />
|
|
</div>
|
|
</SkeletonContainer>
|
|
);
|
|
};
|
|
|
|
const ProfileView = () => {
|
|
const params = useParamsWithFallback();
|
|
const teamId = Number(params.id);
|
|
const { t } = useLocale();
|
|
const router = useRouter();
|
|
const utils = trpc.useUtils();
|
|
const session = useSession();
|
|
|
|
useLayoutEffect(() => {
|
|
document.body.focus();
|
|
}, []);
|
|
|
|
const {
|
|
data: team,
|
|
isPending,
|
|
error,
|
|
} = trpc.viewer.teams.get.useQuery(
|
|
{ teamId },
|
|
{
|
|
enabled: !!teamId,
|
|
}
|
|
);
|
|
|
|
useEffect(
|
|
function refactorMeWithoutEffect() {
|
|
if (error) {
|
|
router.replace("/teams");
|
|
}
|
|
},
|
|
[error]
|
|
);
|
|
const isAdmin = team && checkAdminOrOwner(team.membership.role);
|
|
|
|
const permalink = team
|
|
? `${getTeamUrlSync({
|
|
orgSlug: team.parent ? team.parent.slug : null,
|
|
teamSlug: team.slug,
|
|
})}`
|
|
: "";
|
|
|
|
const isBioEmpty = !team || !team.bio || !team.bio.replace("<p><br></p>", "").length;
|
|
|
|
const deleteTeamMutation = trpc.viewer.teams.delete.useMutation({
|
|
async onSuccess() {
|
|
revalidateTeamsList();
|
|
await utils.viewer.teams.list.invalidate();
|
|
await utils.viewer.eventTypes.getUserEventGroups.invalidate();
|
|
revalidateEventTypesList();
|
|
await utils.viewer.eventTypes.getByViewer.invalidate();
|
|
showToast(t("your_team_disbanded_successfully"), "success");
|
|
router.push(`${WEBAPP_URL}/teams`);
|
|
trackFormbricksAction("team_disbanded");
|
|
},
|
|
async onError(err) {
|
|
showToast(err.message, "error");
|
|
},
|
|
});
|
|
|
|
const removeMemberMutation = trpc.viewer.teams.removeMember.useMutation({
|
|
async onSuccess() {
|
|
await utils.viewer.teams.get.invalidate();
|
|
await utils.viewer.teams.list.invalidate();
|
|
revalidateTeamsList();
|
|
await utils.viewer.eventTypes.invalidate();
|
|
showToast(t("success"), "success");
|
|
},
|
|
async onError(err) {
|
|
showToast(err.message, "error");
|
|
},
|
|
});
|
|
|
|
function deleteTeam() {
|
|
if (team?.id) deleteTeamMutation.mutate({ teamId: team.id });
|
|
}
|
|
|
|
function leaveTeam() {
|
|
if (team?.id && session.data)
|
|
removeMemberMutation.mutate({
|
|
teamIds: [team.id],
|
|
memberIds: [session.data.user.id],
|
|
});
|
|
}
|
|
|
|
if (isPending) {
|
|
return <SkeletonLoader />;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
{isAdmin ? (
|
|
<TeamProfileForm team={team} teamId={teamId} />
|
|
) : (
|
|
<div className="border-subtle flex rounded-b-xl border border-t-0 px-4 py-8 sm:px-6">
|
|
<div className="grow">
|
|
<div>
|
|
<Label className="text-emphasis">{t("team_name")}</Label>
|
|
<p className="text-default text-sm">{team?.name}</p>
|
|
</div>
|
|
{team && !isBioEmpty && (
|
|
<>
|
|
<Label className="text-emphasis mt-5">{t("about")}</Label>
|
|
{/* biome-ignore lint/security/noDangerouslySetInnerHtml: Content is sanitized via markdownToSafeHTML */}
|
|
<div
|
|
className=" text-subtle wrap-break-word text-sm [&_a]:text-blue-500 [&_a]:underline [&_a]:hover:text-blue-600"
|
|
dangerouslySetInnerHTML={{ __html: markdownToSafeHTML(team.bio ?? null) }}
|
|
/>
|
|
</>
|
|
)}
|
|
</div>
|
|
<div>
|
|
<Link href={permalink} passHref={true} target="_blank">
|
|
<LinkIconButton Icon="external-link">{t("preview")}</LinkIconButton>
|
|
</Link>
|
|
<LinkIconButton
|
|
Icon="link"
|
|
onClick={() => {
|
|
navigator.clipboard.writeText(permalink);
|
|
showToast("Copied to clipboard", "success");
|
|
}}>
|
|
{t("copy_link_team")}
|
|
</LinkIconButton>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
<div className="border-subtle mt-6 rounded-lg rounded-b-none border border-b-0 p-6">
|
|
<Label className="mb-0 text-base font-semibold text-red-700">{t("danger_zone")}</Label>
|
|
{team?.membership.role === "OWNER" && (
|
|
<p className="text-subtle text-sm">{t("team_deletion_cannot_be_undone")}</p>
|
|
)}
|
|
</div>
|
|
{team?.membership.role === "OWNER" ? (
|
|
<Dialog>
|
|
<SectionBottomActions align="end">
|
|
<DialogTrigger asChild>
|
|
<Button
|
|
color="destructive"
|
|
className="border"
|
|
StartIcon="trash-2"
|
|
data-testid="disband-team-button">
|
|
{t("disband_team")}
|
|
</Button>
|
|
</DialogTrigger>
|
|
</SectionBottomActions>
|
|
<ConfirmationDialogContent
|
|
variety="danger"
|
|
title={t("disband_team")}
|
|
confirmBtnText={t("confirm_disband_team")}
|
|
onConfirm={() => {
|
|
deleteTeam();
|
|
}}>
|
|
{t("disband_team_confirmation_message")}
|
|
</ConfirmationDialogContent>
|
|
</Dialog>
|
|
) : (
|
|
<Dialog>
|
|
<SectionBottomActions align="end">
|
|
<DialogTrigger asChild>
|
|
<Button color="destructive" className="border" StartIcon="log-out">
|
|
{t("leave_team")}
|
|
</Button>
|
|
</DialogTrigger>
|
|
</SectionBottomActions>
|
|
<ConfirmationDialogContent
|
|
variety="danger"
|
|
title={t("leave_team")}
|
|
confirmBtnText={t("confirm_leave_team")}
|
|
onConfirm={leaveTeam}>
|
|
{t("leave_team_confirmation_message")}
|
|
</ConfirmationDialogContent>
|
|
</Dialog>
|
|
)}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export type TeamProfileFormProps = {
|
|
team: RouterOutputs["viewer"]["teams"]["get"];
|
|
teamId: number;
|
|
};
|
|
|
|
const TeamProfileForm = ({ team, teamId }: TeamProfileFormProps) => {
|
|
const utils = trpc.useUtils();
|
|
const { t } = useLocale();
|
|
const router = useRouter();
|
|
|
|
const teamProfileFormSchema = z.object({
|
|
id: z.number(),
|
|
name: z.string().trim().min(1, t("must_enter_team_name")),
|
|
slug: z
|
|
.string()
|
|
.regex(regex, {
|
|
message: "Url can only have alphanumeric characters(a-z, 0-9) and hyphen(-) symbol.",
|
|
})
|
|
.min(1, t("team_url_required")),
|
|
logo: z.string().nullable(),
|
|
bio: z.string(),
|
|
});
|
|
|
|
type FormValues = z.infer<typeof teamProfileFormSchema>;
|
|
|
|
const mutation = trpc.viewer.teams.update.useMutation({
|
|
onError: (err) => {
|
|
showToast(err.message, "error");
|
|
},
|
|
async onSuccess(res) {
|
|
reset({
|
|
logo: res?.logoUrl,
|
|
name: (res?.name || "") as string,
|
|
bio: (res?.bio || "") as string,
|
|
slug: res?.slug as string,
|
|
});
|
|
await utils.viewer.teams.get.invalidate();
|
|
await utils.viewer.eventTypes.getUserEventGroups.invalidate();
|
|
revalidateEventTypesList();
|
|
// TODO: Not all changes require list invalidation
|
|
await utils.viewer.teams.list.invalidate();
|
|
revalidateTeamsList();
|
|
|
|
if (res?.slug) {
|
|
await revalidateTeamDataCache({
|
|
teamSlug: res.slug,
|
|
orgSlug: team?.parent?.slug ?? null,
|
|
});
|
|
}
|
|
|
|
showToast(t("your_team_updated_successfully"), "success");
|
|
},
|
|
});
|
|
|
|
const defaultValues: FormValues = {
|
|
id: team?.id,
|
|
name: team?.name || "",
|
|
logo: team?.logo || "",
|
|
bio: team?.bio || "",
|
|
slug: team?.slug || ((team?.metadata as Prisma.JsonObject)?.requestedSlug as string) || "",
|
|
};
|
|
|
|
const form = useForm({
|
|
defaultValues,
|
|
resolver: zodResolver(teamProfileFormSchema),
|
|
});
|
|
|
|
const [firstRender, setFirstRender] = useState(true);
|
|
|
|
const {
|
|
formState: { isSubmitting, isDirty },
|
|
reset,
|
|
} = form;
|
|
|
|
const isDisabled = isSubmitting || !isDirty;
|
|
|
|
const publishMutation = trpc.viewer.teams.publish.useMutation({
|
|
async onSuccess(data: { url?: string }) {
|
|
if (data.url) {
|
|
router.push(data.url);
|
|
}
|
|
},
|
|
async onError(err) {
|
|
showToast(err.message, "error");
|
|
},
|
|
});
|
|
|
|
const handleCopy = async (value: string) => {
|
|
try {
|
|
await navigator.clipboard.writeText(value);
|
|
showToast(t("team_id_copied"), "success");
|
|
} catch {
|
|
showToast(t("error_copying_to_clipboard"), "error");
|
|
}
|
|
};
|
|
return (
|
|
<Form
|
|
form={form}
|
|
handleSubmit={(values) => {
|
|
if (team) {
|
|
const variables = {
|
|
name: values.name,
|
|
slug: values.slug,
|
|
bio: values.bio,
|
|
logo: values.logo,
|
|
};
|
|
objectKeys(variables).forEach((key) => {
|
|
if (variables[key as keyof typeof variables] === team?.[key]) delete variables[key];
|
|
});
|
|
mutation.mutate({ id: team.id, ...variables });
|
|
}
|
|
}}>
|
|
<div className="border-subtle border-x px-4 py-8 sm:px-6">
|
|
{!team.parent && (
|
|
<div className="flex items-center pb-8">
|
|
<Controller
|
|
control={form.control}
|
|
name="logo"
|
|
render={({ field: { value, onChange } }) => {
|
|
const showRemoveLogoButton = !!value;
|
|
|
|
return (
|
|
<>
|
|
<Avatar
|
|
alt={form.getValues("name")}
|
|
data-testid="profile-upload-logo"
|
|
imageSrc={getPlaceholderAvatar(value, form.getValues("name"))}
|
|
size="lg"
|
|
/>
|
|
<div className="ms-4 flex gap-2">
|
|
<ImageUploader
|
|
target="logo"
|
|
id="avatar-upload"
|
|
buttonMsg={t("upload_logo")}
|
|
handleAvatarChange={onChange}
|
|
triggerButtonColor={showRemoveLogoButton ? "secondary" : "primary"}
|
|
imageSrc={getPlaceholderAvatar(value, form.getValues("name"))}
|
|
/>
|
|
{showRemoveLogoButton && (
|
|
<Button color="secondary" onClick={() => onChange(null)}>
|
|
{t("remove")}
|
|
</Button>
|
|
)}
|
|
</div>
|
|
</>
|
|
);
|
|
}}
|
|
/>
|
|
</div>
|
|
)}
|
|
|
|
<Controller
|
|
control={form.control}
|
|
name="name"
|
|
render={({ field: { name, value, onChange } }) => (
|
|
<TextField
|
|
name={name}
|
|
label={t("team_name")}
|
|
value={value}
|
|
onChange={(e) => onChange(e?.target.value)}
|
|
/>
|
|
)}
|
|
/>
|
|
<Controller
|
|
control={form.control}
|
|
name="slug"
|
|
render={({ field: { value } }) => (
|
|
<div className="mt-8">
|
|
<TextField
|
|
name="slug"
|
|
label={t("team_url")}
|
|
value={value}
|
|
data-testid="team-url"
|
|
addOnClassname="testid-leading-text-team-url"
|
|
addOnLeading={`${getTeamUrlSync(
|
|
{ orgSlug: team.parent ? team.parent.slug : null, teamSlug: null },
|
|
{
|
|
protocol: false,
|
|
}
|
|
)}`}
|
|
onChange={(e) => {
|
|
form.clearErrors("slug");
|
|
form.setValue("slug", slugify(e?.target.value, true), { shouldDirty: true });
|
|
}}
|
|
/>
|
|
</div>
|
|
)}
|
|
/>
|
|
|
|
<div className="mt-8">
|
|
<TextField
|
|
name="id"
|
|
label={t("team_id")}
|
|
value={teamId}
|
|
disabled={true}
|
|
addOnSuffix={
|
|
<Tooltip content={t("copy_to_clipboard")}>
|
|
<Button
|
|
color="minimal"
|
|
size="sm"
|
|
type="button"
|
|
aria-label="copy team id"
|
|
onClick={() => handleCopy(teamId.toString())}>
|
|
<CopyIcon className="ml-1 h-4 w-4" />
|
|
</Button>
|
|
</Tooltip>
|
|
}
|
|
/>
|
|
</div>
|
|
<div className="mt-8">
|
|
<Label>{t("about")}</Label>
|
|
<Editor
|
|
getText={() => md.render(form.getValues("bio") || "")}
|
|
setText={(value: string) => form.setValue("bio", turndown(value), { shouldDirty: true })}
|
|
excludedToolbarItems={["blockType"]}
|
|
disableLists
|
|
firstRender={firstRender}
|
|
setFirstRender={setFirstRender}
|
|
height="80px"
|
|
/>
|
|
</div>
|
|
<p className="text-default mt-2 text-sm">{t("team_description")}</p>
|
|
</div>
|
|
<SectionBottomActions align="end">
|
|
<Button
|
|
color="primary"
|
|
type="submit"
|
|
loading={mutation.isPending}
|
|
disabled={isDisabled}
|
|
data-testid="update-team-profile">
|
|
{t("update")}
|
|
</Button>
|
|
{IS_TEAM_BILLING_ENABLED &&
|
|
team.slug === null &&
|
|
(team.metadata as Prisma.JsonObject)?.requestedSlug && (
|
|
<Button
|
|
color="secondary"
|
|
className="ml-2"
|
|
type="button"
|
|
onClick={() => {
|
|
publishMutation.mutate({ teamId: team.id });
|
|
}}>
|
|
{t("team_publish")}
|
|
</Button>
|
|
)}
|
|
</SectionBottomActions>
|
|
</Form>
|
|
);
|
|
};
|
|
|
|
export default ProfileView;
|