Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 38 additions & 12 deletions packages/create-invoice-form/src/lib/invoice/form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,35 @@
export let handleNetworkChange: (chainId: string) => void;
export let networks;
export let defaultCurrencies: any = [];
export let payeeAddressError = false;
export let clientAddressError = false;
let validationErrors = {
payeeAddress: false,
clientAddress: false,
sellerInfo: {
email: false,
},
buyerInfo: {
email: false,
},
};
let creatorId = "";
$: {
creatorId = formData.creatorId;
}
const validateEmail = (email: string, type: "sellerInfo" | "buyerInfo") => {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
validationErrors[`${type}`].email = !emailRegex.test(email);
};
const checkPayeeAddress = () => {
payeeAddressError = !checkAddress(formData.payeeAddress);
validationErrors.payeeAddress = !checkAddress(formData.payeeAddress);
};
const checkClientAddress = () => {
clientAddressError = !checkAddress(formData.payerAddress);
validationErrors.clientAddress = !checkAddress(formData.payerAddress);
};
const calculateInputWidth = (value: string) => {
Expand Down Expand Up @@ -177,7 +191,13 @@
type="email"
value={formData.sellerInfo?.email}
placeholder="Email"
handleInput={handleAdditionalInfo}
handleInput={(e) => {
handleAdditionalInfo(e);
}}
onBlur={(e) => validateEmail(e?.target?.value, "sellerInfo")}
error={validationErrors.sellerInfo.email
? "Please enter a valid email"
: ""}
/>
<Input
id="sellerInfo-country"
Expand Down Expand Up @@ -227,10 +247,10 @@
placeholder="Client Wallet Address"
{handleInput}
onBlur={checkClientAddress}
error={validationErrors.clientAddress
? "Please enter a valid Ethereum address"
: ""}
/>
{#if clientAddressError}
<p class="error-address">Please enter a valid Ethereum address</p>
{/if}
<Accordion title="Add Client Info">
<div class="invoice-form-info">
<Input
Expand Down Expand Up @@ -266,7 +286,13 @@
type="email"
value={formData.buyerInfo?.email}
placeholder="Email"
handleInput={handleAdditionalInfo}
handleInput={(e) => {
handleAdditionalInfo(e);
}}
onBlur={(e) => validateEmail(e?.target?.value, "buyerInfo")}
error={validationErrors.buyerInfo.email
? "Please enter a valid email"
: ""}
/>
<Input
id="buyerInfo-country"
Expand Down Expand Up @@ -335,10 +361,10 @@
placeholder="0x..."
{handleInput}
onBlur={checkPayeeAddress}
error={validationErrors.payeeAddress
? "Please enter a valid Ethereum address"
: ""}
/>
{#if payeeAddressError}
<p class="error-address">Please enter a valid Ethereum address</p>
{/if}
</div>
</div>
<div class="invoice-form-dates">
Expand Down
21 changes: 19 additions & 2 deletions shared/components/input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
export let max = 0;
export let style = "";
export let width = "";
export let error: string | null = null;
</script>

<div class="input-wrapper">
{#if label}
<label for={id} class="input-label">{label}</label>
{/if}

<div class={`input-container ${width}`}>
<div class={`${$$slots.icon ? "text-input-icon" : ""}`}>
<slot name="icon" />
Expand All @@ -33,7 +35,7 @@
{placeholder}
maxlength={max}
on:input={handleInput}
class={`textarea-input ${className}`}
class={`textarea-input ${className} ${error ? "input-error" : ""}`}
/>
{:else}
<input
Expand All @@ -46,10 +48,14 @@
{placeholder}
on:blur={onBlur}
on:input={handleInput}
class={`text-input ${className} `}
class={`text-input ${className} ${error ? "input-error" : ""}`}
/>
{/if}
</div>

{#if error?.length > 0}
<p class="error-message">{error}</p>
{/if}
</div>

<style>
Expand Down Expand Up @@ -122,4 +128,15 @@
.input-wrapper .text-input-icon {
margin-right: 10px;
}
/* Error styles */
.input-error {
border-color: #e89e14ee;
}
.error-message {
color: #e89e14ee;
font-size: 12px;
margin-top: 5px;
}
</style>