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 [invoice, setInvoice] = useState("");
|
||||||
const [error, setError] = useState<SubscriptionError>();
|
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);
|
const api = new SnortApi(undefined, publisher);
|
||||||
try {
|
try {
|
||||||
const rsp = await api.renewSubscription(id);
|
const rsp = await api.renewSubscription(id, months);
|
||||||
setInvoice(rsp.pr);
|
setInvoice(rsp.pr);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof SubscriptionError) {
|
if (e instanceof SubscriptionError) {
|
||||||
@ -115,11 +116,20 @@ export default function SubscriptionCard({ sub }: { sub: Subscription }) {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{(isExpired || isNew) && (
|
{(isExpired || isNew) && (
|
||||||
<div className="flex">
|
<div className="flex g8">
|
||||||
<AsyncButton onClick={() => renew(sub.id)}>
|
<div className="flex flex-col g4">
|
||||||
|
<span> </span>
|
||||||
|
<AsyncButton onClick={() => renew(sub.id, months)}>
|
||||||
{isExpired ? <FormattedMessage defaultMessage="Renew" /> : <FormattedMessage defaultMessage="Pay Now" />}
|
{isExpired ? <FormattedMessage defaultMessage="Renew" /> : <FormattedMessage defaultMessage="Pay Now" />}
|
||||||
</AsyncButton>
|
</AsyncButton>
|
||||||
</div>
|
</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()}
|
{isPaid && subFeatures()}
|
||||||
</div>
|
</div>
|
||||||
|
@ -72,8 +72,8 @@ export default class SnortApi {
|
|||||||
return this.#getJsonAuthd<InvoiceResponse>(`api/v1/subscription?type=${type}`, "PUT");
|
return this.#getJsonAuthd<InvoiceResponse>(`api/v1/subscription?type=${type}`, "PUT");
|
||||||
}
|
}
|
||||||
|
|
||||||
renewSubscription(id: string) {
|
renewSubscription(id: string, months = 1) {
|
||||||
return this.#getJsonAuthd<InvoiceResponse>(`api/v1/subscription/${id}/renew`, "GET");
|
return this.#getJsonAuthd<InvoiceResponse>(`api/v1/subscription/${id}/renew?months=${months}`, "GET");
|
||||||
}
|
}
|
||||||
|
|
||||||
listSubscriptions() {
|
listSubscriptions() {
|
||||||
|
Loading…
Reference in New Issue
Block a user