fix: apply credit flow

This commit is contained in:
Arman committed 2024-06-12 18:02:31 +02:00
1 parent 04041f5a9f
commit b01e7f231d
3 files changed
+36 -22

No files matched your search

@@ -17,7 +17,7 @@
let input: HTMLInputElement;
let error: string;
const handleInvalid = (event: Event) => {
function handleInvalid(event: Event) {
event.preventDefault();
if (input.validity.valueMissing) {
@@ -25,7 +25,7 @@
return;
}
error = input.validationMessage;
};
}
async function cardSaved(event: CustomEvent<PaymentMethodData>) {
value = event.detail.$id;
@@ -2,7 +2,7 @@
import { DropList } from '$lib/components';
import { clickOnEnter } from '$lib/helpers/a11y';
import { createEventDispatcher, onMount } from 'svelte';
import { Label } from '.';
import { Helper, Label } from '.';
/* eslint no-undef: "off" */
type Option = $$Generic<{
@@ -36,6 +36,7 @@
let element: HTMLInputElement;
let hasFocus = false;
let selected: number = null;
let error: string;
$: if (!hasFocus) {
selected = null;
@@ -105,7 +106,18 @@
dispatch('reset');
}
function handleInvalid(event: Event) {
event.preventDefault();
if (element.validity.valueMissing) {
error = 'This field is required';
return;
}
error = element.validationMessage;
}
$: showClearBtn = (hasFocus && search) || value;
$: if (value || search) error = null;
</script>
<li
@@ -147,6 +159,7 @@
bind:this={element}
on:focus={() => (hasFocus = true)}
on:click={() => (hasFocus = true)}
on:invalid={handleInvalid}
on:input={handleInput}
on:keydown={handleKeydown} />
{/if}
@@ -205,6 +218,9 @@
{/if}
</svelte:fragment>
</DropList>
{#if error}
<Helper class="u-position-relative" type="warning">{error}</Helper>
{/if}
</li>
<style>
+17 -19
View File
@@ -47,6 +47,7 @@
let selectedOrgId: string = null;
let formComponent: Form;
let couponForm: Form;
let isSubmitting = writable(false);
let methods: PaymentList;
let paymentMethodId: string;
@@ -86,6 +87,7 @@
}
async function handleSubmit() {
if (!couponForm.checkValidity()) return;
try {
let org: Organization;
// Create new org
@@ -179,29 +181,16 @@
(team) => team.$id === selectedOrgId
) as Organization;
$: isButtonDisabled =
checkButtonDisabled(selectedOrgId, name, paymentMethodId) ||
couponData?.status !== 'active';
$: campaign = campaigns.get(data?.couponData?.campaign ?? data?.campaign);
function checkButtonDisabled(id: string | null, name: string | null, method: string | null) {
if (id === newOrgId) {
return !name || !method;
} else if (id && selectedOrg?.billingPlan === BillingPlan.PRO) {
return !selectedOrg?.paymentMethodId;
} else if (id) {
return !method;
} else return true;
}
</script>
<svelte:head>
<title>Get started - Appwrite</title>
<title>Apply credits - Appwrite</title>
</svelte:head>
<WizardSecondaryContainer href={previousPage} bind:showExitModal>
<WizardSecondaryHeader confirmExit on:exit={() => (showExitModal = true)}>
Get started
Apply credits
</WizardSecondaryHeader>
<WizardSecondaryContent>
<Form bind:this={formComponent} onSubmit={handleSubmit} bind:isSubmitting>
@@ -236,10 +225,11 @@
{/if}
</FormList>
</Form>
<Form onSubmit={addCoupon}>
<Form bind:this={couponForm} onSubmit={addCoupon}>
<FormList>
{#if !data?.couponData?.code && selectedOrgId}
<InputText
required
disabled={!!couponData?.credits}
bind:value={coupon}
placeholder="Enter coupon code"
@@ -301,12 +291,20 @@
<Button fullWidthMobile secondary on:click={() => (showExitModal = true)}>Cancel</Button>
<Button
fullWidthMobile
on:click={() => formComponent.triggerSubmit()}
disabled={$isSubmitting || isButtonDisabled}>
on:click={() => {
if (formComponent.checkValidity() && couponForm.checkValidity()) {
handleSubmit();
}
}}
disabled={$isSubmitting}>
{#if $isSubmitting}
<span class="loader is-small is-transparent u-line-height-1-5" aria-hidden="true" />
{/if}
Create Organization
{#if selectedOrgId === newOrgId}
Create Organization
{:else}
Apply Credits
{/if}
</Button>
</WizardSecondaryFooter>
<svelte:fragment slot="exit">