refactor: rewrite useSubscription with RQ
This commit is contained in:
38
packages/web/src/hooks/useSubscription.ee.js
Normal file
38
packages/web/src/hooks/useSubscription.ee.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
import useFormatMessage from './useFormatMessage';
|
||||
import api from 'helpers/api';
|
||||
|
||||
export default function useSubscription() {
|
||||
const formatMessage = useFormatMessage();
|
||||
|
||||
const { data, isLoading: isSubscriptionLoading } = useQuery({
|
||||
queryKey: ['subscription'],
|
||||
queryFn: async ({ signal }) => {
|
||||
const { data } = await api.get(`/v1/users/me/subscription`, {
|
||||
signal,
|
||||
});
|
||||
|
||||
return data;
|
||||
},
|
||||
});
|
||||
const subscription = data?.data;
|
||||
|
||||
const cancellationEffectiveDate = subscription?.cancellationEffectiveDate;
|
||||
|
||||
const hasCancelled = !!cancellationEffectiveDate;
|
||||
|
||||
if (isSubscriptionLoading || !hasCancelled) return null;
|
||||
|
||||
const cancellationEffectiveDateObject = DateTime.fromISO(
|
||||
cancellationEffectiveDate,
|
||||
);
|
||||
|
||||
return {
|
||||
message: formatMessage('subscriptionCancelledAlert.text', {
|
||||
date: cancellationEffectiveDateObject.toFormat('DDD'),
|
||||
}),
|
||||
cancellationEffectiveDate: cancellationEffectiveDateObject,
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user