Files
calendar/apps/web/lib/hooks/settings/platform/billing/useUnsubscribeTeamToStripe.ts
T
fbe8cf8223 fix: cancel platform subscription on dashboard (#20787)
* add new endpoint to cancel user subscription

* remove comments

* add delete button to frontend

* update correct request method

* fixup

* frontend for cancelling subscription

* better warning message

* better function name

* update locales

* better error handling in case stripe api call fails

* rename teamId to organizationId

---------

Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
2025-04-28 08:41:25 +01:00

37 lines
918 B
TypeScript

import { useMutation } from "@tanstack/react-query";
import { SUCCESS_STATUS } from "@calcom/platform-constants";
import type { ApiResponse } from "@calcom/platform-types";
export const useUnsubscribeTeamToStripe = (
{ onSuccess, onError, teamId }: { teamId?: number | null; onSuccess: () => void; onError: () => void } = {
onSuccess: () => {
return;
},
onError: () => {
return;
},
}
) => {
const mutation = useMutation<ApiResponse, unknown>({
mutationFn: (data) => {
return fetch(`/api/v2/billing/${teamId}/unsubscribe`, {
method: "delete",
headers: { "Content-type": "application/json" },
}).then((res) => res?.json());
},
onSuccess: (data) => {
if (data.status === SUCCESS_STATUS) {
onSuccess?.();
} else {
onError?.();
}
},
onError: () => {
onError?.();
},
});
return mutation;
};