Feat(SW-1275) cancel booking my stay * feat(SW-1276) UI implementation Desktop part 1 for MyStay * feat(SW-1276) UI implementation Desktop part 2 for MyStay * feat(SW-1276) UI implementation Mobile part 1 for MyStay * refactor: move files from MyStay/MyStay to MyStay * feat(SW-1276) Sidepeek implementation * feat(SW-1276): Refactoring * feat(SW-1276) UI implementation Mobile part 2 for MyStay * feat(SW-1276): translations * feat(SW-1276) fixed skeleton * feat(SW-1276): Added missing translations * feat(SW-1276) fixed translations * feat(SW-1275) cancel modal * feat(SW-1275): Mutate cancel booking * feat(SW-1275) added translations * feat(SW-1275) match current cancellationReason * feat(SW-1275) Added modal for manage stay * feat(SW-1275) Added missing icon * feat(SW-1275) New Dont cancel button * feat(SW-1275) Added preperation for Cancellation number * feat(SW-1275): added --modal-box-shadow * feat(SW-1718) Add to calendar * feat(SW-1718) general add to calendar Approved-by: Niclas Edenvin
87 lines
2.0 KiB
TypeScript
87 lines
2.0 KiB
TypeScript
import { useState } from "react"
|
||
import { useIntl } from "react-intl"
|
||
|
||
import { trpc } from "@/lib/trpc/client"
|
||
|
||
import { toast } from "@/components/TempDesignSystem/Toasts"
|
||
import useLang from "@/hooks/useLang"
|
||
|
||
import type { CancelStayProps } from ".."
|
||
|
||
export default function useCancelStay({
|
||
booking,
|
||
setBookingStatus,
|
||
handleCloseModal,
|
||
handleBackToManageStay,
|
||
}: Omit<CancelStayProps, "hotel">) {
|
||
const intl = useIntl()
|
||
const lang = useLang()
|
||
const [currentStep, setCurrentStep] = useState(1)
|
||
const [isLoading, setIsLoading] = useState(false)
|
||
|
||
const cancelStay = trpc.booking.cancel.useMutation({
|
||
onMutate: () => setIsLoading(true),
|
||
onSuccess: (result) => {
|
||
if (!result) {
|
||
toast.error(
|
||
intl.formatMessage({
|
||
id: "Something went wrong. Please try again later.",
|
||
})
|
||
)
|
||
return
|
||
}
|
||
|
||
setBookingStatus()
|
||
toast.success(
|
||
intl.formatMessage(
|
||
{
|
||
id: "Your stay was cancelled. Cancellation cost: 0 {currency}. We’re sorry to see that the plans didn’t work out",
|
||
},
|
||
{ currency: booking.currencyCode }
|
||
)
|
||
)
|
||
},
|
||
onError: () => {
|
||
toast.error(
|
||
intl.formatMessage({
|
||
id: "Something went wrong. Please try again later.",
|
||
})
|
||
)
|
||
},
|
||
onSettled: () => {
|
||
handleCloseModal()
|
||
},
|
||
})
|
||
|
||
function handleCancelStay() {
|
||
if (!booking.confirmationNumber) {
|
||
toast.error(
|
||
intl.formatMessage({
|
||
id: "Something went wrong. Please try again later.",
|
||
})
|
||
)
|
||
return
|
||
}
|
||
|
||
cancelStay.mutate({
|
||
confirmationNumber: booking.confirmationNumber,
|
||
language: lang,
|
||
})
|
||
}
|
||
|
||
function handleCloseCancelStay() {
|
||
setCurrentStep(1)
|
||
setIsLoading(false)
|
||
handleBackToManageStay()
|
||
}
|
||
|
||
return {
|
||
currentStep,
|
||
isLoading,
|
||
handleCancelStay,
|
||
handleCloseCancelStay,
|
||
handleBack: () => setCurrentStep(1),
|
||
handleForward: () => setCurrentStep(2),
|
||
}
|
||
}
|