|
@@ -20,6 +20,7 @@ import PoNumber from '@/features/group-management/components/add-seats/po-number
|
|
|
import CostSummary from '@/features/group-management/components/add-seats/cost-summary'
|
|
import CostSummary from '@/features/group-management/components/add-seats/cost-summary'
|
|
|
import RequestStatus from '@/features/group-management/components/request-status'
|
|
import RequestStatus from '@/features/group-management/components/request-status'
|
|
|
import useAsync from '@/shared/hooks/use-async'
|
|
import useAsync from '@/shared/hooks/use-async'
|
|
|
|
|
+import useAsyncWithCancel from '@/shared/hooks/use-async-with-cancel'
|
|
|
import getMeta from '@/utils/meta'
|
|
import getMeta from '@/utils/meta'
|
|
|
import { FetchError, postJSON } from '@/infrastructure/fetch-json'
|
|
import { FetchError, postJSON } from '@/infrastructure/fetch-json'
|
|
|
import { debugConsole } from '@/utils/debugging'
|
|
import { debugConsole } from '@/utils/debugging'
|
|
@@ -50,7 +51,6 @@ function AddSeats() {
|
|
|
const [addSeatsInputError, setAddSeatsInputError] = useState<string>()
|
|
const [addSeatsInputError, setAddSeatsInputError] = useState<string>()
|
|
|
const [poNumberInputError, setPoNumberInputError] = useState<string>()
|
|
const [poNumberInputError, setPoNumberInputError] = useState<string>()
|
|
|
const [shouldContactSales, setShouldContactSales] = useState(false)
|
|
const [shouldContactSales, setShouldContactSales] = useState(false)
|
|
|
- const controller = useAbortController()
|
|
|
|
|
const { signal: addSeatsSignal } = useAbortController()
|
|
const { signal: addSeatsSignal } = useAbortController()
|
|
|
const { signal: contactSalesSignal } = useAbortController()
|
|
const { signal: contactSalesSignal } = useAbortController()
|
|
|
const {
|
|
const {
|
|
@@ -60,7 +60,8 @@ function AddSeats() {
|
|
|
data: costSummaryData,
|
|
data: costSummaryData,
|
|
|
reset: resetCostSummaryData,
|
|
reset: resetCostSummaryData,
|
|
|
error: errorCostSummary,
|
|
error: errorCostSummary,
|
|
|
- } = useAsync<CostSummaryData, FetchError>()
|
|
|
|
|
|
|
+ cancelAll: cancelCostSummaryRequest,
|
|
|
|
|
+ } = useAsyncWithCancel<CostSummaryData, FetchError>()
|
|
|
const [isAddingSeats, setIsAddingSeats] = useState(false)
|
|
const [isAddingSeats, setIsAddingSeats] = useState(false)
|
|
|
const [isErrorAddingSeats, setIsErrorAddingSeats] = useState(false)
|
|
const [isErrorAddingSeats, setIsErrorAddingSeats] = useState(false)
|
|
|
const [isSuccessAddingSeats, setIsSuccessAddingSeats] = useState(false)
|
|
const [isSuccessAddingSeats, setIsSuccessAddingSeats] = useState(false)
|
|
@@ -85,14 +86,21 @@ function AddSeats() {
|
|
|
|
|
|
|
|
const debouncedCostSummaryRequest = useMemo(
|
|
const debouncedCostSummaryRequest = useMemo(
|
|
|
() =>
|
|
() =>
|
|
|
- debounce((value: number, signal: AbortSignal) => {
|
|
|
|
|
- const post = postJSON('/user/subscription/group/add-users/preview', {
|
|
|
|
|
- signal,
|
|
|
|
|
- body: { adding: value },
|
|
|
|
|
|
|
+ debounce((value: number) => {
|
|
|
|
|
+ cancelCostSummaryRequest()
|
|
|
|
|
+ const post = (signal: AbortSignal) =>
|
|
|
|
|
+ postJSON('/user/subscription/group/add-users/preview', {
|
|
|
|
|
+ body: { adding: value },
|
|
|
|
|
+ signal,
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ runAsyncCostSummary(post).catch(error => {
|
|
|
|
|
+ if (error.name !== 'AbortError') {
|
|
|
|
|
+ debugConsole.error(error)
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
- runAsyncCostSummary(post).catch(debugConsole.error)
|
|
|
|
|
}, 500),
|
|
}, 500),
|
|
|
- [runAsyncCostSummary]
|
|
|
|
|
|
|
+ [runAsyncCostSummary, cancelCostSummaryRequest]
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
const debouncedTrackUserEnterSeatNumberEvent = useMemo(
|
|
const debouncedTrackUserEnterSeatNumberEvent = useMemo(
|
|
@@ -168,14 +176,15 @@ function AddSeats() {
|
|
|
debouncedCostSummaryRequest.cancel()
|
|
debouncedCostSummaryRequest.cancel()
|
|
|
shouldContactSales = true
|
|
shouldContactSales = true
|
|
|
} else {
|
|
} else {
|
|
|
- debouncedCostSummaryRequest(seats, controller.signal)
|
|
|
|
|
|
|
+ debouncedCostSummaryRequest(seats)
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
debouncedTrackUserEnterSeatNumberEvent.cancel()
|
|
debouncedTrackUserEnterSeatNumberEvent.cancel()
|
|
|
debouncedCostSummaryRequest.cancel()
|
|
debouncedCostSummaryRequest.cancel()
|
|
|
|
|
+ cancelCostSummaryRequest()
|
|
|
|
|
+ resetCostSummaryData()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- resetCostSummaryData()
|
|
|
|
|
setShouldContactSales(shouldContactSales)
|
|
setShouldContactSales(shouldContactSales)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -374,7 +383,6 @@ function AddSeats() {
|
|
|
required
|
|
required
|
|
|
className="w-25"
|
|
className="w-25"
|
|
|
name="seats"
|
|
name="seats"
|
|
|
- disabled={isLoadingCostSummary}
|
|
|
|
|
onChange={handleSeatsChange}
|
|
onChange={handleSeatsChange}
|
|
|
isInvalid={Boolean(addSeatsInputError)}
|
|
isInvalid={Boolean(addSeatsInputError)}
|
|
|
/>
|
|
/>
|