|
26 | 26 | export let handleNetworkChange: (chainId: string) => void; |
27 | 27 | export let networks; |
28 | 28 | 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 | + }; |
31 | 40 |
|
32 | 41 | let creatorId = ""; |
33 | 42 |
|
34 | 43 | $: { |
35 | 44 | creatorId = formData.creatorId; |
36 | 45 | } |
37 | 46 |
|
| 47 | + const validateEmail = (email: string, type: "sellerInfo" | "buyerInfo") => { |
| 48 | + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; |
| 49 | + validationErrors[`${type}`].email = !emailRegex.test(email); |
| 50 | + }; |
| 51 | +
|
38 | 52 | const checkPayeeAddress = () => { |
39 | | - payeeAddressError = !checkAddress(formData.payeeAddress); |
| 53 | + validationErrors.payeeAddress = !checkAddress(formData.payeeAddress); |
40 | 54 | }; |
41 | 55 |
|
42 | 56 | const checkClientAddress = () => { |
43 | | - clientAddressError = !checkAddress(formData.payerAddress); |
| 57 | + validationErrors.clientAddress = !checkAddress(formData.payerAddress); |
44 | 58 | }; |
45 | 59 |
|
46 | 60 | const calculateInputWidth = (value: string) => { |
|
178 | 192 | type="email" |
179 | 193 | value={formData.sellerInfo?.email} |
180 | 194 | 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 | + : ""} |
182 | 202 | /> |
183 | 203 | <Input |
184 | 204 | id="sellerInfo-country" |
|
228 | 248 | placeholder="Client Wallet Address" |
229 | 249 | {handleInput} |
230 | 250 | onBlur={checkClientAddress} |
| 251 | + error={validationErrors.clientAddress |
| 252 | + ? "Please enter a valid Ethereum address" |
| 253 | + : ""} |
231 | 254 | /> |
232 | | - {#if clientAddressError} |
233 | | - <p class="error-address">Please enter a valid Ethereum address</p> |
234 | | - {/if} |
235 | 255 | <Accordion title="Add Client Info"> |
236 | 256 | <div class="invoice-form-info"> |
237 | 257 | <Input |
|
267 | 287 | type="email" |
268 | 288 | value={formData.buyerInfo?.email} |
269 | 289 | 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 | + : ""} |
271 | 297 | /> |
272 | 298 | <Input |
273 | 299 | id="buyerInfo-country" |
|
336 | 362 | placeholder="0x..." |
337 | 363 | {handleInput} |
338 | 364 | onBlur={checkPayeeAddress} |
| 365 | + error={validationErrors.payeeAddress |
| 366 | + ? "Please enter a valid Ethereum address" |
| 367 | + : ""} |
339 | 368 | /> |
340 | | - {#if payeeAddressError} |
341 | | - <p class="error-address">Please enter a valid Ethereum address</p> |
342 | | - {/if} |
343 | 369 | </div> |
344 | 370 | </div> |
345 | 371 | <div class="invoice-form-dates"> |
|
0 commit comments