feat: sub renew months
This commit is contained in:
parent
9f6a030a11
commit
6479a18cb2
@ -26,11 +26,12 @@ export default function SubscriptionCard({ sub }: { sub: Subscription }) {
|
||||
|
||||
const [invoice, setInvoice] = useState("");
|
||||
const [error, setError] = useState<SubscriptionError>();
|
||||
const [months, setMonths] = useState(1);
|
||||
|
||||
async function renew(id: string) {
|
||||
async function renew(id: string, months: number) {
|
||||
const api = new SnortApi(undefined, publisher);
|
||||
try {
|
||||
const rsp = await api.renewSubscription(id);
|
||||
const rsp = await api.renewSubscription(id, months);
|
||||
setInvoice(rsp.pr);
|
||||
} catch (e) {
|
||||
if (e instanceof SubscriptionError) {
|
||||
@ -115,10 +116,19 @@ export default function SubscriptionCard({ sub }: { sub: Subscription }) {
|
||||
)}
|
||||
</div>
|
||||
{(isExpired || isNew) && (
|
||||
<div className="flex">
|
||||
<AsyncButton onClick={() => renew(sub.id)}>
|
||||
{isExpired ? <FormattedMessage defaultMessage="Renew" /> : <FormattedMessage defaultMessage="Pay Now" />}
|
||||
</AsyncButton>
|
||||
<div className="flex g8">
|
||||
<div className="flex flex-col g4">
|
||||
<span> </span>
|
||||
<AsyncButton onClick={() => renew(sub.id, months)}>
|
||||
{isExpired ? <FormattedMessage defaultMessage="Renew" /> : <FormattedMessage defaultMessage="Pay Now" />}
|
||||
</AsyncButton>
|
||||
</div>
|
||||
<div className="flex flex-col g4">
|
||||
<small>
|
||||
<FormattedMessage defaultMessage="Months" />
|
||||
</small>
|
||||
<input type="number" value={months} onChange={e => setMonths(Number(e.target.value))} min={1} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{isPaid && subFeatures()}
|
||||
|
@ -72,8 +72,8 @@ export default class SnortApi {
|
||||
return this.#getJsonAuthd<InvoiceResponse>(`api/v1/subscription?type=${type}`, "PUT");
|
||||
}
|
||||
|
||||
renewSubscription(id: string) {
|
||||
return this.#getJsonAuthd<InvoiceResponse>(`api/v1/subscription/${id}/renew`, "GET");
|
||||
renewSubscription(id: string, months = 1) {
|
||||
return this.#getJsonAuthd<InvoiceResponse>(`api/v1/subscription/${id}/renew?months=${months}`, "GET");
|
||||
}
|
||||
|
||||
listSubscriptions() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user