-
Notifications
You must be signed in to change notification settings - Fork 0
feat: register Crove CRM native card in App Store #64
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { usePathname } from "next/navigation"; | ||
| import AppCard from "@calcom/app-store/_components/AppCard"; | ||
| import useIsAppEnabled from "@calcom/app-store/_utils/useIsAppEnabled"; | ||
| import type { EventTypeAppCardComponent } from "@calcom/app-store/types"; | ||
| import { WEBAPP_URL } from "@calcom/lib/constants"; | ||
|
|
||
| const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({ app, eventType, onAppInstallSuccess }) { | ||
| const pathname = usePathname(); | ||
| const { enabled, updateEnabled } = useIsAppEnabled(app); | ||
|
|
||
| return ( | ||
| <AppCard | ||
| onAppInstallSuccess={onAppInstallSuccess} | ||
| returnTo={`${WEBAPP_URL}${pathname}?tabName=apps`} | ||
| app={app} | ||
| teamId={eventType.team?.id || undefined} | ||
| switchOnClick={(e) => { | ||
| updateEnabled(e); | ||
| }} | ||
| switchChecked={enabled} | ||
| hideAppCardOptions | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default EventTypeAppCard; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "name": "Crove CRM", | ||
| "slug": "crovecrm", | ||
| "type": "crovecrm_crm", | ||
| "logo": "icon.svg", | ||
| "url": "https://crm.crove.com", | ||
| "variant": "crm", | ||
| "categories": ["crm"], | ||
| "extendsFeature": "EventType", | ||
| "publisher": "MetaDOS LLC", | ||
| "email": "help@crove.com", | ||
| "description": "Automatically synchronize booked appointments, attendee contacts, and meeting timelines directly into Crove CRM with Organization and Team attribution.", | ||
| "isTemplate": false, | ||
| "__createdUsingCli": true, | ||
| "dirName": "crovecrm" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from "./lib/CrmService"; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,131 @@ | ||||||||||||||||||||||
| import { CroveCrmService } from "@calcom/features/crove-crm"; | ||||||||||||||||||||||
| import type { CalendarEvent, EventBusyDate, IntegrationCalendar } from "@calcom/types/Calendar"; | ||||||||||||||||||||||
| import type { CredentialPayload } from "@calcom/types/Credential"; | ||||||||||||||||||||||
| import type { CRM, Contact, ContactCreateInput, CrmEvent } from "@calcom/types/CrmService"; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| export class CroveCrmIntegrationService implements CRM { | ||||||||||||||||||||||
| private crm: CroveCrmService; | ||||||||||||||||||||||
| private credential: CredentialPayload; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| constructor(credential: CredentialPayload) { | ||||||||||||||||||||||
| this.credential = credential; | ||||||||||||||||||||||
| const key = credential.key as { api_key?: string; api_url?: string } | undefined; | ||||||||||||||||||||||
| this.crm = new CroveCrmService(key?.api_key, key?.api_url); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| async createEvent(event: CalendarEvent, _contacts?: Contact[]): Promise<CrmEvent | undefined> { | ||||||||||||||||||||||
| const result = await this.crm.syncBookingEvent({ | ||||||||||||||||||||||
| triggerEvent: "BOOKING_CREATED", | ||||||||||||||||||||||
| payload: { | ||||||||||||||||||||||
| uid: event.uid || undefined, | ||||||||||||||||||||||
| title: event.title, | ||||||||||||||||||||||
| startTime: event.startTime, | ||||||||||||||||||||||
| endTime: event.endTime, | ||||||||||||||||||||||
| organizer: event.organizer, | ||||||||||||||||||||||
| attendees: event.attendees.map((a) => ({ | ||||||||||||||||||||||
| email: a.email, | ||||||||||||||||||||||
| name: a.name, | ||||||||||||||||||||||
| timeZone: a.timeZone, | ||||||||||||||||||||||
| })), | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return { | ||||||||||||||||||||||
| id: event.uid || `crovecrm_${Date.now()}`, | ||||||||||||||||||||||
| uid: event.uid || undefined, | ||||||||||||||||||||||
| type: "crovecrm", | ||||||||||||||||||||||
| additionalInfo: result, | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| async updateEvent(uid: string, event: CalendarEvent): Promise<CrmEvent> { | ||||||||||||||||||||||
| const result = await this.crm.syncBookingEvent({ | ||||||||||||||||||||||
| triggerEvent: "BOOKING_RESCHEDULED", | ||||||||||||||||||||||
| payload: { | ||||||||||||||||||||||
| uid, | ||||||||||||||||||||||
| title: event.title, | ||||||||||||||||||||||
| startTime: event.startTime, | ||||||||||||||||||||||
| endTime: event.endTime, | ||||||||||||||||||||||
| organizer: event.organizer, | ||||||||||||||||||||||
| attendees: event.attendees.map((a) => ({ | ||||||||||||||||||||||
| email: a.email, | ||||||||||||||||||||||
| name: a.name, | ||||||||||||||||||||||
| timeZone: a.timeZone, | ||||||||||||||||||||||
| })), | ||||||||||||||||||||||
|
Comment on lines
+50
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return { | ||||||||||||||||||||||
| id: uid, | ||||||||||||||||||||||
| uid, | ||||||||||||||||||||||
| type: "crovecrm", | ||||||||||||||||||||||
| additionalInfo: result, | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| async deleteEvent(uid: string, event: CalendarEvent): Promise<void> { | ||||||||||||||||||||||
| await this.crm.syncBookingEvent({ | ||||||||||||||||||||||
| triggerEvent: "BOOKING_CANCELLED", | ||||||||||||||||||||||
| payload: { | ||||||||||||||||||||||
| uid, | ||||||||||||||||||||||
| title: event?.title || "Meeting", | ||||||||||||||||||||||
| startTime: event?.startTime || new Date().toISOString(), | ||||||||||||||||||||||
| endTime: event?.endTime, | ||||||||||||||||||||||
| organizer: event?.organizer || { email: "host@crove.com" }, | ||||||||||||||||||||||
| attendees: event?.attendees?.map((a) => ({ | ||||||||||||||||||||||
| email: a.email, | ||||||||||||||||||||||
| name: a.name, | ||||||||||||||||||||||
| timeZone: a.timeZone, | ||||||||||||||||||||||
| })) || [], | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| async getContacts(_options?: { emails: string | string[]; includeOwner?: boolean }): Promise<Contact[]> { | ||||||||||||||||||||||
| return []; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| async createContacts( | ||||||||||||||||||||||
| contactsToCreate: ContactCreateInput[], | ||||||||||||||||||||||
| _organizerEmail?: string | ||||||||||||||||||||||
| ): Promise<Contact[]> { | ||||||||||||||||||||||
| const created: Contact[] = []; | ||||||||||||||||||||||
| for (const c of contactsToCreate) { | ||||||||||||||||||||||
| if (c.email) { | ||||||||||||||||||||||
| const res = await this.crm.upsertContact({ | ||||||||||||||||||||||
| email: c.email, | ||||||||||||||||||||||
| name: c.name, | ||||||||||||||||||||||
| phone: c.phone || undefined, | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| created.push({ | ||||||||||||||||||||||
| id: res.contactId || c.email, | ||||||||||||||||||||||
| email: c.email, | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| return created; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| getAppOptions() { | ||||||||||||||||||||||
| return {}; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| async getAvailability( | ||||||||||||||||||||||
| _dateFrom: string, | ||||||||||||||||||||||
| _dateTo: string, | ||||||||||||||||||||||
| _selectedCalendars: IntegrationCalendar[] | ||||||||||||||||||||||
| ): Promise<EventBusyDate[]> { | ||||||||||||||||||||||
| return []; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| async listCalendars(_event?: CalendarEvent): Promise<IntegrationCalendar[]> { | ||||||||||||||||||||||
| return []; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| export default function BuildCrmService( | ||||||||||||||||||||||
| credential: CredentialPayload, | ||||||||||||||||||||||
| _appOptions?: Record<string, unknown> | ||||||||||||||||||||||
| ): CRM { | ||||||||||||||||||||||
| return new CroveCrmIntegrationService(credential); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "name": "@calcom/crovecrm", | ||
| "version": "0.0.0", | ||
| "main": "./index.ts", | ||
| "types": "./index.ts", | ||
| "private": true, | ||
| "devDependencies": { | ||
| "@calcom/types": "workspace:*" | ||
| } | ||
|
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The package imports from "devDependencies": {
"@calcom/features": "workspace:*",
"@calcom/lib": "workspace:*",
"@calcom/types": "workspace:*"
} |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { z } from "zod"; | ||
| import { eventTypeAppCardZod } from "../eventTypeAppCardZod"; | ||
|
|
||
| export const appKeysSchema = z.object({ | ||
| api_key: z.string().optional(), | ||
| api_url: z.string().optional(), | ||
| }); | ||
|
|
||
| export const appDataSchema = eventTypeAppCardZod; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
event.attendees.mapdirectly can lead to a runtime error ifevent.attendeesis undefined or null. It is safer to use optional chaining and provide a fallback empty array, similar to how it is handled indeleteEvent.