Skip to content

Commit 7eb433a

Browse files
committed
Merge branch 'main' of github.com:RequestNetwork/web-components into 143-add-builderid-and-createdwith-to-request-invoicing
2 parents a752e16 + 36a6d71 commit 7eb433a

File tree

2 files changed

+57
-14
lines changed

2 files changed

+57
-14
lines changed

packages/create-invoice-form/src/lib/invoice/form.svelte

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,35 @@
2626
export let handleNetworkChange: (chainId: string) => void;
2727
export let networks;
2828
export let defaultCurrencies: any = [];
29-
export let payeeAddressError = false;
30-
export let clientAddressError = false;
29+
30+
let validationErrors = {
31+
payeeAddress: false,
32+
clientAddress: false,
33+
sellerInfo: {
34+
email: false,
35+
},
36+
buyerInfo: {
37+
email: false,
38+
},
39+
};
3140
3241
let creatorId = "";
3342
3443
$: {
3544
creatorId = formData.creatorId;
3645
}
3746
47+
const validateEmail = (email: string, type: "sellerInfo" | "buyerInfo") => {
48+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
49+
validationErrors[`${type}`].email = !emailRegex.test(email);
50+
};
51+
3852
const checkPayeeAddress = () => {
39-
payeeAddressError = !checkAddress(formData.payeeAddress);
53+
validationErrors.payeeAddress = !checkAddress(formData.payeeAddress);
4054
};
4155
4256
const checkClientAddress = () => {
43-
clientAddressError = !checkAddress(formData.payerAddress);
57+
validationErrors.clientAddress = !checkAddress(formData.payerAddress);
4458
};
4559
4660
const calculateInputWidth = (value: string) => {
@@ -178,7 +192,13 @@
178192
type="email"
179193
value={formData.sellerInfo?.email}
180194
placeholder="Email"
181-
handleInput={handleAdditionalInfo}
195+
handleInput={(e) => {
196+
handleAdditionalInfo(e);
197+
}}
198+
onBlur={(e) => validateEmail(e?.target?.value, "sellerInfo")}
199+
error={validationErrors.sellerInfo.email
200+
? "Please enter a valid email"
201+
: ""}
182202
/>
183203
<Input
184204
id="sellerInfo-country"
@@ -228,10 +248,10 @@
228248
placeholder="Client Wallet Address"
229249
{handleInput}
230250
onBlur={checkClientAddress}
251+
error={validationErrors.clientAddress
252+
? "Please enter a valid Ethereum address"
253+
: ""}
231254
/>
232-
{#if clientAddressError}
233-
<p class="error-address">Please enter a valid Ethereum address</p>
234-
{/if}
235255
<Accordion title="Add Client Info">
236256
<div class="invoice-form-info">
237257
<Input
@@ -267,7 +287,13 @@
267287
type="email"
268288
value={formData.buyerInfo?.email}
269289
placeholder="Email"
270-
handleInput={handleAdditionalInfo}
290+
handleInput={(e) => {
291+
handleAdditionalInfo(e);
292+
}}
293+
onBlur={(e) => validateEmail(e?.target?.value, "buyerInfo")}
294+
error={validationErrors.buyerInfo.email
295+
? "Please enter a valid email"
296+
: ""}
271297
/>
272298
<Input
273299
id="buyerInfo-country"
@@ -336,10 +362,10 @@
336362
placeholder="0x..."
337363
{handleInput}
338364
onBlur={checkPayeeAddress}
365+
error={validationErrors.payeeAddress
366+
? "Please enter a valid Ethereum address"
367+
: ""}
339368
/>
340-
{#if payeeAddressError}
341-
<p class="error-address">Please enter a valid Ethereum address</p>
342-
{/if}
343369
</div>
344370
</div>
345371
<div class="invoice-form-dates">

shared/components/input.svelte

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
export let max = 0;
1515
export let style = "";
1616
export let width = "";
17+
export let error: string | null = null;
1718
</script>
1819

1920
<div class="input-wrapper">
2021
{#if label}
2122
<label for={id} class="input-label">{label}</label>
2223
{/if}
24+
2325
<div class={`input-container ${width}`}>
2426
<div class={`${$$slots.icon ? "text-input-icon" : ""}`}>
2527
<slot name="icon" />
@@ -33,7 +35,7 @@
3335
{placeholder}
3436
maxlength={max}
3537
on:input={handleInput}
36-
class={`textarea-input ${className}`}
38+
class={`textarea-input ${className} ${error ? "input-error" : ""}`}
3739
/>
3840
{:else}
3941
<input
@@ -46,10 +48,14 @@
4648
{placeholder}
4749
on:blur={onBlur}
4850
on:input={handleInput}
49-
class={`text-input ${className} `}
51+
class={`text-input ${className} ${error ? "input-error" : ""}`}
5052
/>
5153
{/if}
5254
</div>
55+
56+
{#if error?.length > 0}
57+
<p class="error-message">{error}</p>
58+
{/if}
5359
</div>
5460

5561
<style>
@@ -122,4 +128,15 @@
122128
.input-wrapper .text-input-icon {
123129
margin-right: 10px;
124130
}
131+
132+
/* Error styles */
133+
.input-error {
134+
border-color: #e89e14ee;
135+
}
136+
137+
.error-message {
138+
color: #e89e14ee;
139+
font-size: 12px;
140+
margin-top: 5px;
141+
}
125142
</style>

0 commit comments

Comments
 (0)