feat: cancellation reason
This commit is contained in:
parent
a91b26766a
commit
599b9ac772
|
|
@ -6,13 +6,15 @@ import { Organization, User } from '@prisma/client';
|
|||
import { BillingSubscribeDto } from '@gitroom/nestjs-libraries/dtos/billing/billing.subscribe.dto';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { GetUserFromRequest } from '@gitroom/nestjs-libraries/user/user.from.request';
|
||||
import { NotificationService } from '@gitroom/nestjs-libraries/database/prisma/notifications/notification.service';
|
||||
|
||||
@ApiTags('Billing')
|
||||
@Controller('/billing')
|
||||
export class BillingController {
|
||||
constructor(
|
||||
private _subscriptionService: SubscriptionService,
|
||||
private _stripeService: StripeService
|
||||
private _stripeService: StripeService,
|
||||
private _notificationService: NotificationService
|
||||
) {}
|
||||
|
||||
@Get('/check/:id')
|
||||
|
|
@ -53,7 +55,16 @@ export class BillingController {
|
|||
}
|
||||
|
||||
@Post('/cancel')
|
||||
cancel(@GetOrgFromRequest() org: Organization) {
|
||||
async cancel(
|
||||
@GetOrgFromRequest() org: Organization,
|
||||
@Body() body: { feedback: string }
|
||||
) {
|
||||
await this._notificationService.sendEmail(
|
||||
process.env.EMAIL_FROM_ADDRESS,
|
||||
'Subscription Cancelled',
|
||||
`Organization ${org.name} has cancelled their subscription because: ${body.feedback}`
|
||||
);
|
||||
|
||||
return this._stripeService.setToCancel(org.id);
|
||||
}
|
||||
|
||||
|
|
@ -83,6 +94,10 @@ export class BillingController {
|
|||
throw new Error('Unauthorized');
|
||||
}
|
||||
|
||||
await this._subscriptionService.addSubscription(org.id, user.id, body.subscription);
|
||||
await this._subscriptionService.addSubscription(
|
||||
org.id,
|
||||
user.id,
|
||||
body.subscription
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
'use client';
|
||||
|
||||
import { Slider } from '@gitroom/react/form/slider';
|
||||
import { FC, useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import React, { FC, useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { Button } from '@gitroom/react/form/button';
|
||||
import { sortBy } from 'lodash';
|
||||
import { Track } from '@gitroom/react/form/track';
|
||||
|
|
@ -20,6 +20,10 @@ import { useUser } from '@gitroom/frontend/components/layout/user.context';
|
|||
import interClass from '@gitroom/react/helpers/inter.font';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useVariables } from '@gitroom/react/helpers/variable.context';
|
||||
import { useModals } from '@mantine/modals';
|
||||
import { AddProviderComponent } from '@gitroom/frontend/components/launches/add.provider.component';
|
||||
import { TopTitle } from '@gitroom/frontend/components/launches/helpers/top.title.component';
|
||||
import { Textarea } from '@gitroom/react/form/textarea';
|
||||
|
||||
export interface Tiers {
|
||||
month: Array<{
|
||||
|
|
@ -149,15 +153,71 @@ export const Features: FC<{
|
|||
);
|
||||
};
|
||||
|
||||
const Info: FC<{ proceed: (feedback: string) => void }> = (props) => {
|
||||
const [feedback, setFeedback] = useState('');
|
||||
const modal = useModals();
|
||||
|
||||
const cancel = useCallback(() => {
|
||||
props.proceed(feedback);
|
||||
modal.closeAll();
|
||||
}, [modal, feedback]);
|
||||
|
||||
return (
|
||||
<div className="relative flex gap-[20px] flex-col flex-1 rounded-[4px] border border-customColor6 bg-sixth p-[16px] pt-0 w-[500px]">
|
||||
<TopTitle title="Oh no" />
|
||||
<button
|
||||
className="outline-none absolute right-[20px] top-[15px] mantine-UnstyledButton-root mantine-ActionIcon-root hover:bg-tableBorder cursor-pointer mantine-Modal-close mantine-1dcetaa"
|
||||
type="button"
|
||||
>
|
||||
<svg
|
||||
viewBox="0 0 15 15"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="16"
|
||||
height="16"
|
||||
>
|
||||
<path
|
||||
d="M11.7816 4.03157C12.0062 3.80702 12.0062 3.44295 11.7816 3.2184C11.5571 2.99385 11.193 2.99385 10.9685 3.2184L7.50005 6.68682L4.03164 3.2184C3.80708 2.99385 3.44301 2.99385 3.21846 3.2184C2.99391 3.44295 2.99391 3.80702 3.21846 4.03157L6.68688 7.49999L3.21846 10.9684C2.99391 11.193 2.99391 11.557 3.21846 11.7816C3.44301 12.0061 3.80708 12.0061 4.03164 11.7816L7.50005 8.31316L10.9685 11.7816C11.193 12.0061 11.5571 12.0061 11.7816 11.7816C12.0062 11.557 12.0062 11.193 11.7816 10.9684L8.31322 7.49999L11.7816 4.03157Z"
|
||||
fill="currentColor"
|
||||
fillRule="evenodd"
|
||||
clipRule="evenodd"
|
||||
></path>
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<div>
|
||||
We are sorry to see you go :(
|
||||
<br />
|
||||
Would you mind shortly tell us what we could have done better?
|
||||
</div>
|
||||
<div>
|
||||
<Textarea
|
||||
label={'Feedback'}
|
||||
name="feedback"
|
||||
disableForm={true}
|
||||
value={feedback}
|
||||
onChange={(e) => setFeedback(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Button disabled={feedback.length < 20} onClick={cancel}>
|
||||
Cancel Subscription
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const MainBillingComponent: FC<{
|
||||
sub?: Subscription;
|
||||
}> = (props) => {
|
||||
const { sub } = props;
|
||||
const {isGeneral} = useVariables();
|
||||
const { isGeneral } = useVariables();
|
||||
const { mutate } = useSWRConfig();
|
||||
const fetch = useFetch();
|
||||
const toast = useToaster();
|
||||
const user = useUser();
|
||||
const modal = useModals();
|
||||
const router = useRouter();
|
||||
|
||||
const [subscription, setSubscription] = useState<Subscription | undefined>(
|
||||
|
|
@ -236,10 +296,28 @@ export const MainBillingComponent: FC<{
|
|||
'Cancel Subscription'
|
||||
))
|
||||
) {
|
||||
const info = await new Promise((res) => {
|
||||
modal.openModal({
|
||||
title: '',
|
||||
withCloseButton: false,
|
||||
classNames: {
|
||||
modal: 'bg-transparent text-textColor',
|
||||
},
|
||||
children: <Info proceed={(e) => res(e)} />,
|
||||
size: 'auto',
|
||||
});
|
||||
});
|
||||
|
||||
setLoading(true);
|
||||
const { cancel_at } = await (
|
||||
await fetch('/billing/cancel', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
feedback: info,
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
})
|
||||
).json();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue