Skip to content

Commit 2a97f89

Browse files
authored
fix(condo): DOMA-11270 add mutation emitter for new hooks (#5926)
1 parent 28f7d6c commit 2a97f89

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

apps/condo/domains/onboarding/contexts/TourContext.tsx

+21-9
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@ export const TourProvider: React.FC = ({ children }) => {
4545
const organizationId = organization?.id || null
4646
const organizationType = organization?.type || null
4747

48-
const [getTourSteps, { refetch: refetchSteps }] = useGetTourStepsLazyQuery()
48+
const [getTourSteps, {
49+
refetch: refetchSteps,
50+
}] = useGetTourStepsLazyQuery({
51+
variables: {
52+
where: {
53+
organization: {
54+
id: organizationId,
55+
},
56+
},
57+
},
58+
})
4959

5060
const [updateTourStep] = useUpdateTourStepMutation()
5161

@@ -57,11 +67,11 @@ export const TourProvider: React.FC = ({ children }) => {
5767
sender: getClientSideSenderInfo(),
5868
},
5969
},
60-
onCompleted: async () => await getTourSteps({
61-
variables: {
62-
where: { organization: { id: organizationId } },
63-
},
64-
}),
70+
onCompleted: async () => {
71+
if (organizationId) {
72+
await refetchSteps()
73+
}
74+
},
6575
})
6676

6777
useEffect(() => {
@@ -100,15 +110,17 @@ export const TourProvider: React.FC = ({ children }) => {
100110
const updateStepIfNotCompleted = useCallback(async (type: TourStepTypeType, nextRoute?: string) => {
101111
if (organizationType !== MANAGING_COMPANY_TYPE) return
102112

103-
const { data: fetchResult } = await getTourSteps({
113+
const {
114+
data: tourStepData,
115+
} = await getTourSteps({
104116
variables: {
105117
where: {
106118
organization: { id: organizationId },
107119
type,
108120
},
109121
},
110122
})
111-
const tourStep = fetchResult?.tourSteps.filter(Boolean)[0] || null
123+
const tourStep = tourStepData?.tourSteps.filter(Boolean)[0] || null
112124

113125
if (!tourStep) return
114126

@@ -151,7 +163,7 @@ export const TourProvider: React.FC = ({ children }) => {
151163
}
152164

153165
case 'updateProperty': {
154-
if (data?.obj?.map) return
166+
if (!data?.obj?.map) return
155167

156168
await updateStepIfNotCompleted(TourStepTypeType.CreatePropertyMap)
157169
break

apps/condo/domains/onboarding/queries/TourStep.graphql

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ query getTourSteps ($where: TourStepWhereInput!, $sortBy: [SortTourStepsBy!]) {
1111
}
1212

1313
mutation updateTourStep ($id: ID!, $data: TourStepUpdateInput!) {
14-
tourStep: updateTourStep(id: $id, data: $data) {
14+
tourStep: updateTourStep (
15+
id: $id,
16+
data: $data
17+
) {
1518
id
1619
}
1720
}

apps/condo/domains/ticket/components/TicketForm/CreateTicketForm.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import React, { useCallback, useMemo, useState, useEffect } from 'react'
1414

1515
import { useCachePersistor } from '@open-condo/apollo'
1616
import { getClientSideSenderInfo } from '@open-condo/codegen/utils/userId'
17-
import { useApolloClient } from '@open-condo/next/apollo'
17+
import { MUTATION_RESULT_EVENT, MutationEmitter, useApolloClient } from '@open-condo/next/apollo'
1818
import { useAuth } from '@open-condo/next/auth'
1919
import { useIntl } from '@open-condo/next/intl'
2020
import { useOrganization } from '@open-condo/next/organization'
@@ -149,6 +149,9 @@ export const CreateTicketForm: React.FC = () => {
149149
onCompleted: async (ticketData) => {
150150
const ticket = ticketData?.ticket
151151
addTicketToQueryCacheForTicketCardList(ticket)
152+
MutationEmitter.emit(MUTATION_RESULT_EVENT, {
153+
name: 'createTicket',
154+
})
152155
if (redirectToClientCard) {
153156
const clientPhone = ticket?.clientPhone
154157
const ticketPropertyId = ticket?.property?.id

0 commit comments

Comments
 (0)