import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile'; import styled from '@emotion/styled'; import { useMemo, useState } from 'react'; import { useParams, useSearchParams } from 'react-router-dom'; import { Button, H2Title, IconBox, IconButton, IconNorthStar, IconPlus, IconRefresh, IconTrash, Section, useIcons, } from 'twenty-ui'; import { AnalyticsActivityGraph } from '@/analytics/components/AnalyticsActivityGraph'; import { AnalyticsGraphEffect } from '@/analytics/components/AnalyticsGraphEffect'; import { AnalyticsGraphDataInstanceContext } from '@/analytics/states/contexts/AnalyticsGraphDataInstanceContext'; import { isAnalyticsEnabledState } from '@/client-config/states/isAnalyticsEnabledState'; import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems'; import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer'; import { useWebhookUpdateForm } from '@/settings/developers/hooks/useWebhookUpdateForm'; import { SettingsPath } from '@/types/SettingsPath'; import { Select, SelectOption } from '@/ui/input/components/Select'; import { TextArea } from '@/ui/input/components/TextArea'; import { TextInput } from '@/ui/input/components/TextInput'; import { ConfirmationModal } from '@/ui/layout/modal/components/ConfirmationModal'; import { SubMenuTopBarContainer } from '@/ui/layout/page/components/SubMenuTopBarContainer'; import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled'; import { Trans, useLingui } from '@lingui/react/macro'; import { useRecoilValue } from 'recoil'; import { isDefined } from 'twenty-shared'; import { FeatureFlagKey } from '~/generated/graphql'; import { getSettingsPath } from '~/utils/navigation/getSettingsPath'; const OBJECT_DROPDOWN_WIDTH = 340; const ACTION_DROPDOWN_WIDTH = 140; const OBJECT_MOBILE_WIDTH = 150; const ACTION_MOBILE_WIDTH = 140; const StyledFilterRow = styled.div<{ isMobile: boolean }>` display: grid; grid-template-columns: ${({ isMobile }) => isMobile ? `${OBJECT_MOBILE_WIDTH}px ${ACTION_MOBILE_WIDTH}px auto` : `${OBJECT_DROPDOWN_WIDTH}px ${ACTION_DROPDOWN_WIDTH}px auto`}; gap: ${({ theme }) => theme.spacing(2)}; margin-bottom: ${({ theme }) => theme.spacing(2)}; align-items: center; `; const StyledPlaceholder = styled.div` height: ${({ theme }) => theme.spacing(8)}; width: ${({ theme }) => theme.spacing(8)}; `; export const SettingsDevelopersWebhooksDetail = () => { const { t } = useLingui(); const { objectMetadataItems } = useObjectMetadataItems(); const isAnalyticsEnabled = useRecoilValue(isAnalyticsEnabledState); const isMobile = useIsMobile(); const { getIcon } = useIcons(); const { webhookId = '' } = useParams(); const [searchParams] = useSearchParams(); const isCreationMode = isDefined(searchParams.get('creationMode')); const { formData, title, loading, isTargetUrlValid, updateWebhook, updateOperation, removeOperation, deleteWebhook, } = useWebhookUpdateForm({ webhookId, isCreationMode, }); const [isDeleteWebhookModalOpen, setIsDeleteWebhookModalOpen] = useState(false); const isAnalyticsV2Enabled = useIsFeatureEnabled( FeatureFlagKey.IsAnalyticsV2Enabled, ); const fieldTypeOptions: SelectOption[] = useMemo( () => [ { value: '*', label: t`All Objects`, Icon: IconNorthStar }, ...objectMetadataItems.map((item) => ({ value: item.nameSingular, label: item.labelPlural, Icon: getIcon(item.icon), })), ], [objectMetadataItems, getIcon, t], ); const actionOptions: SelectOption[] = [ { value: '*', label: t`All Actions`, Icon: IconNorthStar }, { value: 'created', label: t`Created`, Icon: IconPlus }, { value: 'updated', label: t`Updated`, Icon: IconRefresh }, { value: 'deleted', label: t`Deleted`, Icon: IconTrash }, ]; if (loading || !formData) { return <>; } const confirmationText = t`yes`; return (
{ updateWebhook({ targetUrl }); }} error={!isTargetUrlValid ? t`Please enter a valid URL` : undefined} fullWidth autoFocus={formData.targetUrl.trim() === ''} />