chore: replaced coupon type with sdk one

This commit is contained in:
ChiragAgg5k
2025-03-05 15:52:09 +05:30
parent e800b0baaa
commit be53138d55
11 changed files with 28 additions and 35 deletions
@@ -1,15 +1,15 @@
<script lang="ts">
import { Button, FormList, InputText } from '$lib/elements/forms';
import { formatCurrency } from '$lib/helpers/numbers';
import type { Coupon } from '$lib/sdk/billing';
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
export let required = false;
export let coupon: string = '';
export let couponData: Partial<Coupon> = {
export let couponData: Partial<Models.Coupon> = {
code: null,
status: null,
credits: null
@@ -1,9 +1,9 @@
<script lang="ts">
import { tooltip } from '$lib/actions/tooltip';
import { formatCurrency } from '$lib/helpers/numbers';
import type { Coupon } from '$lib/sdk/billing';
import type { Models } from '@appwrite.io/console';
export let couponData: Partial<Coupon> = {
export let couponData: Partial<Models.Coupon> = {
code: null,
status: null,
credits: null
@@ -1,10 +1,10 @@
<script lang="ts">
import { formatCurrency } from '$lib/helpers/numbers';
import type { Coupon } from '$lib/sdk/billing';
import type { Models } from '@appwrite.io/console';
export let label: string;
export let value: number;
export let couponData: Partial<Coupon> = {
export let couponData: Partial<Models.Coupon> = {
code: null,
status: null,
credits: null
@@ -1,18 +1,19 @@
<script lang="ts">
import { FormList, InputChoice, InputNumber } from '$lib/elements/forms';
import { formatCurrency } from '$lib/helpers/numbers';
import type { Coupon, Estimation } from '$lib/sdk/billing';
import type { Estimation } from '$lib/sdk/billing';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
import { AppwriteException } from '@appwrite.io/console';
import Card from '../card.svelte';
import DiscountsApplied from './discountsApplied.svelte';
import { addNotification } from '$lib/stores/notifications';
export let organizationId: string | undefined = undefined;
export let billingPlan: string;
export let collaborators: string[];
export let fixedCoupon = false;
export let couponData: Partial<Coupon>;
export let couponData: Partial<Models.Coupon>;
export let billingBudget: number;
@@ -1,16 +1,16 @@
<script lang="ts">
import { Modal } from '$lib/components';
import { Button, FormList, InputText } from '$lib/elements/forms';
import type { Coupon } from '$lib/sdk/billing';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
export let show = false;
let error: string = null;
let coupon: string = '';
export let couponData: Partial<Coupon> = {
export let couponData: Partial<Models.Coupon> = {
code: null,
status: null,
credits: null
+2 -2
View File
@@ -5,16 +5,16 @@
import AppwriteLogoLight from '$lib/images/appwrite-logo-light.svg';
import LoginDark from '$lib/images/login/login-dark-mode.png';
import LoginLight from '$lib/images/login/login-light-mode.png';
import type { Coupon } from '$lib/sdk/billing';
import { app } from '$lib/stores/app';
import type { Campaign } from '$lib/stores/campaigns';
import { getCampaignImageUrl } from '$routes/(public)/card/helpers';
import type { Models } from '@appwrite.io/console';
export const imgLight = LoginLight;
export const imgDark = LoginDark;
export let campaign: Campaign = null;
export let coupon: Coupon = null;
export let coupon: Models.Coupon = null;
$: variation = ((coupon?.campaign ?? campaign) ? campaign?.template : 'default') as
| 'default'
+2 -12
View File
@@ -91,16 +91,6 @@ export type EstimationDeleteOrganization = {
unpaidInvoices: Invoice[];
};
export type Coupon = {
$id: string;
code: string;
credits: number;
expiration: string;
status: string; // 'active' | 'disabled' | 'expired'
validity: number;
campaign?: string;
};
export type Credit = {
/**
* Credit ID.
@@ -895,7 +885,7 @@ export class Billing {
}
}
async getCouponAccount(couponId: string): Promise<Coupon> {
async getCouponAccount(couponId: string): Promise<Models.Coupon> {
const path = `/account/coupons/${couponId}`;
const params = {
couponId
@@ -911,7 +901,7 @@ export class Billing {
);
}
async getCoupon(couponId: string): Promise<Coupon> {
async getCoupon(couponId: string): Promise<Models.Coupon> {
const path = `/console/coupons/${couponId}`;
const params = {
couponId
+2 -2
View File
@@ -1,13 +1,13 @@
import { base } from '$app/paths';
import type { Coupon } from '$lib/sdk/billing.js';
import type { Campaign } from '$lib/stores/campaigns.js';
import { sdk } from '$lib/stores/sdk.js';
import type { Models } from '@appwrite.io/console';
import { redirect } from '@sveltejs/kit';
export const load = async ({ url }) => {
// Has promo code
if (url.searchParams.has('code')) {
let couponData: Coupon;
let couponData: Models.Coupon;
let campaign: Campaign;
const code = url.searchParams.get('code');
try {
@@ -14,16 +14,17 @@
WizardSecondaryContent,
WizardSecondaryFooter
} from '$lib/layout';
import type { Coupon, PaymentList } from '$lib/sdk/billing';
import type { PaymentList } from '$lib/sdk/billing';
import { isOrganization, tierToPlan } from '$lib/stores/billing';
import { addNotification } from '$lib/stores/notifications';
import {
organizationList,
type OrganizationError,
type Organization
type Organization,
type OrganizationError
} from '$lib/stores/organization';
import { sdk } from '$lib/stores/sdk';
import { confirmPayment } from '$lib/stores/stripe';
import type { Models } from '@appwrite.io/console';
import { ID } from '@appwrite.io/console';
import { onMount } from 'svelte';
import { writable } from 'svelte/store';
@@ -47,7 +48,7 @@
let billingPlan: BillingPlan = BillingPlan.FREE;
let paymentMethodId: string;
let collaborators: string[] = [];
let couponData: Partial<Coupon> = {
let couponData: Partial<Models.Coupon> = {
code: null,
status: null,
credits: null
@@ -1,14 +1,14 @@
<script lang="ts">
import { CouponInput } from '$lib/components/billing';
import { WizardStep } from '$lib/layout';
import type { Coupon } from '$lib/sdk/billing';
import { sdk } from '$lib/stores/sdk';
import { wizard } from '$lib/stores/wizard';
import type { Models } from '@appwrite.io/console';
import { onMount } from 'svelte';
import { addCreditWizardStore } from '../store';
let coupon: string;
export let couponData: Partial<Coupon> = {
export let couponData: Partial<Models.Coupon> = {
code: null,
status: null,
credits: null
@@ -27,7 +27,7 @@
WizardSecondaryContent,
WizardSecondaryFooter
} from '$lib/layout';
import { type Coupon, type PaymentList } from '$lib/sdk/billing';
import { type PaymentList } from '$lib/sdk/billing';
import { isOrganization, plansInfo, tierToPlan, type Tier } from '$lib/stores/billing';
import { addNotification } from '$lib/stores/notifications';
import {
@@ -40,6 +40,7 @@
import { confirmPayment } from '$lib/stores/stripe';
import { user } from '$lib/stores/user';
import { VARS } from '$lib/system';
import type { Models } from '@appwrite.io/console';
import { onMount } from 'svelte';
import { writable } from 'svelte/store';
@@ -66,7 +67,7 @@
if (m.userEmail !== $user.email) return m.userEmail;
})
?.filter(Boolean) ?? [];
let couponData: Partial<Coupon> = {
let couponData: Partial<Models.Coupon> = {
code: null,
status: null,
credits: null