File tree 2 files changed +38
-15
lines changed
packages/features/insights
2 files changed +38
-15
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ import classNames from "@calcom/lib/classNames";
29
29
import { useCopy } from "@calcom/lib/hooks/useCopy" ;
30
30
import { useLocale } from "@calcom/lib/hooks/useLocale" ;
31
31
import { BookingStatus } from "@calcom/prisma/enums" ;
32
- import { RoutingFormFieldType , isValidRoutingFormFieldType } from "@calcom/routing-forms/lib/FieldTypes" ;
32
+ import { RoutingFormFieldType } from "@calcom/routing-forms/lib/FieldTypes" ;
33
33
import { trpc , type RouterOutputs } from "@calcom/trpc" ;
34
34
import {
35
35
Badge ,
@@ -258,7 +258,7 @@ export function RoutingFormResponsesTable() {
258
258
useInsightsParameters ( ) ;
259
259
260
260
const {
261
- data : headersRaw ,
261
+ data : headers ,
262
262
isLoading : isHeadersLoading ,
263
263
isSuccess : isHeadersSuccess ,
264
264
} = trpc . viewer . insights . routingFormResponsesHeaders . useQuery ( {
@@ -268,11 +268,6 @@ export function RoutingFormResponsesTable() {
268
268
routingFormId,
269
269
} ) ;
270
270
271
- const headers = useMemo ( ( ) => {
272
- if ( ! headersRaw ) return ;
273
- return headersRaw . filter ( ( header ) => header . label && isValidRoutingFormFieldType ( header . type ) ) ;
274
- } , [ headersRaw ] ) ;
275
-
276
271
const { data : forms } = trpc . viewer . insights . getRoutingFormsForFilters . useQuery ( {
277
272
userId,
278
273
teamId,
Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ import mapKeys from "lodash/mapKeys";
4
4
// eslint-disable-next-line no-restricted-imports
5
5
import startCase from "lodash/startCase" ;
6
6
7
+ import {
8
+ RoutingFormFieldType ,
9
+ isValidRoutingFormFieldType ,
10
+ } from "@calcom/app-store/routing-forms/lib/FieldTypes" ;
7
11
import { zodFields as routingFormFieldsSchema } from "@calcom/app-store/routing-forms/zod" ;
8
12
import dayjs from "@calcom/dayjs" ;
9
13
import type { ColumnFilter , TypedColumnFilter } from "@calcom/features/data-table" ;
@@ -617,14 +621,38 @@ class RoutingEventsInsights {
617
621
} ) ;
618
622
619
623
const fields = routingFormFieldsSchema . parse ( routingForms . map ( ( f ) => f . fields ) . flat ( ) ) ;
620
- const headers = fields ?. map ( ( f ) => {
621
- return {
622
- id : f . id ,
623
- label : f . label ,
624
- type : f . type ,
625
- options : f . options ,
626
- } ;
627
- } ) ;
624
+ const ids = new Set < string > ( ) ;
625
+ const headers = ( fields || [ ] )
626
+ . map ( ( f ) => {
627
+ return {
628
+ id : f . id ,
629
+ label : f . label ,
630
+ type : f . type ,
631
+ options : f . options ,
632
+ } ;
633
+ } )
634
+ . filter ( ( field ) => {
635
+ if ( ! field . label || ! isValidRoutingFormFieldType ( field . type ) ) {
636
+ return false ;
637
+ }
638
+ if (
639
+ field . type === RoutingFormFieldType . SINGLE_SELECT ||
640
+ field . type === RoutingFormFieldType . MULTI_SELECT
641
+ ) {
642
+ return field . options && field . options . length > 0 ;
643
+ }
644
+ return true ;
645
+ } )
646
+ . filter ( ( field ) => {
647
+ // Remove duplicate fields
648
+ // because we aggregate fields from multiple routing forms.
649
+ if ( ids . has ( field . id ) ) {
650
+ return false ;
651
+ } else {
652
+ ids . add ( field . id ) ;
653
+ return true ;
654
+ }
655
+ } ) ;
628
656
629
657
return headers ;
630
658
}
You can’t perform that action at this time.
0 commit comments