-
Notifications
You must be signed in to change notification settings - Fork 2
BUGFIX: validate Merchant Emails field on save #329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,13 @@ export function ApiCredentials() { | |
| const hasCredentials = username.length > 0 && password.length > 0 | ||
| const hasBusinessLicense = isTest ? settings.testHasBusinessLicense : settings.liveHasBusinessLicense | ||
|
|
||
| const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ | ||
| const invalidEmails = merchantEmails | ||
| .split(',') | ||
| .map(e => e.trim()) | ||
| .filter(e => e.length > 0 && !EMAIL_RE.test(e)) | ||
| const merchantEmailsInvalid = invalidEmails.length > 0 | ||
|
Comment on lines
+41
to
+45
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
|
||
| const setField = (field: string, value: string | boolean) => { | ||
| updateSettings({ [`${prefix}${field.charAt(0).toUpperCase() + field.slice(1)}`]: value } as Record<string, string | boolean>) | ||
| } | ||
|
|
@@ -242,7 +249,14 @@ export function ApiCredentials() { | |
| placeholder={t('enterMerchantEmails')} | ||
| value={merchantEmails} | ||
| onChange={(e) => setField('merchantEmails', e.target.value)} | ||
| aria-invalid={merchantEmailsInvalid} | ||
| className={merchantEmailsInvalid ? 'sp-border-destructive focus-visible:sp-ring-destructive' : ''} | ||
| /> | ||
| {merchantEmailsInvalid && ( | ||
| <p className="sp-text-xs sp-text-destructive"> | ||
| {t('invalidMerchantEmails')}: {invalidEmails.join(', ')} | ||
| </p> | ||
| )} | ||
| <p className="sp-text-xs sp-text-muted-foreground"> | ||
| {t('separateEmails')} | ||
| </p> | ||
|
|
@@ -342,7 +356,7 @@ export function ApiCredentials() { | |
| <Button | ||
| className="sp-min-w-[120px]" | ||
| onClick={saveCredentials} | ||
| disabled={saving || !hasCredentials || credentialStatus === 'invalid' || credentialStatus === 'checking'} | ||
| disabled={saving || !hasCredentials || credentialStatus === 'invalid' || credentialStatus === 'checking' || merchantEmailsInvalid} | ||
| aria-label={saving ? t('saving') : undefined} | ||
| > | ||
| {saving ? <Loader2 className="sp-h-4 sp-w-4 sp-animate-spin" /> : t('saveChanges')} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The email validation logic should be moved before the API credentials validation (lines 166-180). Validating local input data first is more efficient as it avoids unnecessary and potentially slow remote API calls if the merchant emails are already invalid.