(props: Props)
| 20 | type: IIntegrationConfig['type']; |
| 21 | } |
| 22 | export default function AddIntegration(props: Props) { |
| 23 | const { organizationId } = useAppParams(); |
| 24 | const trpc = useTRPC(); |
| 25 | const query = useQuery( |
| 26 | trpc.integration.get.queryOptions( |
| 27 | { |
| 28 | id: props.id ?? '', |
| 29 | }, |
| 30 | { |
| 31 | enabled: !!props.id, |
| 32 | }, |
| 33 | ), |
| 34 | ); |
| 35 | |
| 36 | const integration = INTEGRATIONS.find((i) => i.type === props.type); |
| 37 | |
| 38 | const renderCard = () => { |
| 39 | if (!integration) { |
| 40 | return null; |
| 41 | } |
| 42 | return ( |
| 43 | <div className="card bg-def-100"> |
| 44 | <IntegrationCardContent {...integration} /> |
| 45 | </div> |
| 46 | ); |
| 47 | }; |
| 48 | |
| 49 | const navigate = useNavigate(); |
| 50 | const client = useQueryClient(); |
| 51 | const handleSuccess = () => { |
| 52 | toast.success('Integration created'); |
| 53 | popModal(); |
| 54 | client.invalidateQueries(trpc.integration.list.pathFilter()); |
| 55 | client.invalidateQueries( |
| 56 | trpc.integration.get.queryFilter({ id: props.id }), |
| 57 | ); |
| 58 | navigate({ |
| 59 | to: '/$organizationId/integrations/installed', |
| 60 | params: { |
| 61 | organizationId, |
| 62 | }, |
| 63 | }); |
| 64 | }; |
| 65 | |
| 66 | const renderForm = () => { |
| 67 | if (props.id && query.isLoading) { |
| 68 | return null; |
| 69 | } |
| 70 | |
| 71 | switch (integration?.type) { |
| 72 | case 'webhook': |
| 73 | return ( |
| 74 | <WebhookIntegrationForm |
| 75 | defaultValues={query.data} |
| 76 | onSuccess={handleSuccess} |
| 77 | /> |
| 78 | ); |
| 79 | case 'discord': |
nothing calls this directly
no test coverage detected