-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Domains: Implement multi-target email forwards (#98837)
- Loading branch information
Showing
35 changed files
with
1,012 additions
and
754 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
client/lib/domains/email-forwarding/has-duplicated-email-forwards.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,3 @@ | ||
import emailValidator from 'email-validator'; | ||
import { mapValues } from 'lodash'; | ||
import { hasDuplicatedEmailForwards } from 'calypso/lib/domains/email-forwarding/has-duplicated-email-forwards'; | ||
|
||
function validateAllFields( fieldValues, existingEmailForwards = [] ) { | ||
return mapValues( fieldValues, ( value, fieldName ) => { | ||
const isValid = validateField( { | ||
value, | ||
name: fieldName, | ||
} ); | ||
|
||
if ( ! isValid ) { | ||
return [ 'Invalid' ]; | ||
} | ||
|
||
if ( fieldName !== 'mailbox' ) { | ||
return []; | ||
} | ||
|
||
return hasDuplicatedEmailForwards( value, existingEmailForwards ) ? [ 'Duplicated' ] : []; | ||
} ); | ||
} | ||
|
||
function validateField( { name, value } ) { | ||
switch ( name ) { | ||
case 'mailbox': | ||
return /^[a-z0-9._+-]{1,64}$/i.test( value ) && ! /(^\.)|(\.{2,})|(\.$)/.test( value ); | ||
case 'destination': | ||
return emailValidator.validate( value ); | ||
default: | ||
return true; | ||
} | ||
} | ||
|
||
export { getEmailForwardsCount } from './get-email-forwards-count'; | ||
export { hasEmailForwards } from './has-email-forwards'; | ||
export { getDomainsWithEmailForwards } from './get-domains-with-email-forwards'; | ||
export { validateAllFields }; |
80 changes: 80 additions & 0 deletions
80
client/my-sites/email/email-forwarding/actions-menu/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { ConfirmationDialog } from '@automattic/components'; | ||
import { | ||
__experimentalHeading as Heading, | ||
__experimentalText as Text, | ||
__experimentalVStack as VStack, | ||
DropdownMenu, | ||
} from '@wordpress/components'; | ||
import { rotateLeft, trash, moreHorizontalMobile } from '@wordpress/icons'; | ||
import { useTranslate } from 'i18n-calypso'; | ||
import { useState } from 'react'; | ||
import { getEmailForwardAddress } from 'calypso/lib/emails'; | ||
import { useResend, useRemove } from '../hooks'; | ||
import type { Mailbox } from '../../../../data/emails/types'; | ||
import './style.scss'; | ||
|
||
export const ActionsMenu = ( { mailbox }: { mailbox: Mailbox } ) => { | ||
const [ isOpen, setIsOpen ] = useState( false ); | ||
const remove = useRemove( { mailbox } ); | ||
const resend = useResend( { mailbox } ); | ||
const translate = useTranslate(); | ||
|
||
const handleConfirm = () => { | ||
remove( mailbox.mailbox, mailbox.domain, getEmailForwardAddress( mailbox ) ); | ||
setIsOpen( false ); | ||
}; | ||
|
||
const handleCancel = () => { | ||
setIsOpen( false ); | ||
}; | ||
|
||
return ( | ||
<> | ||
<ConfirmationDialog | ||
isOpen={ isOpen } | ||
onConfirm={ handleConfirm } | ||
onCancel={ handleCancel } | ||
cancelButtonText={ translate( 'Cancel' ) } | ||
confirmButtonText={ translate( 'Remove' ) } | ||
> | ||
<VStack> | ||
<Heading level={ 3 }> | ||
{ translate( 'Are you sure you want to remove this email forward?' ) } | ||
</Heading> | ||
<Text> | ||
{ translate( | ||
"This will remove it from our records and if it's not used in another forward, it will require reverification if added again." | ||
) } | ||
</Text> | ||
</VStack> | ||
</ConfirmationDialog> | ||
<DropdownMenu | ||
icon={ moreHorizontalMobile } | ||
label={ translate( 'More options' ) } | ||
controls={ | ||
mailbox.warnings?.length | ||
? [ | ||
{ | ||
title: 'Resend', | ||
icon: rotateLeft, | ||
onClick: () => | ||
resend( mailbox.mailbox, mailbox.domain, getEmailForwardAddress( mailbox ) ), | ||
}, | ||
{ | ||
title: 'Remove', | ||
icon: trash, | ||
onClick: () => setIsOpen( true ), | ||
}, | ||
] | ||
: [ | ||
{ | ||
title: 'Remove', | ||
icon: trash, | ||
onClick: () => setIsOpen( true ), | ||
}, | ||
] | ||
} | ||
/> | ||
</> | ||
); | ||
}; |
6 changes: 6 additions & 0 deletions
6
client/my-sites/email/email-forwarding/actions-menu/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Delete me once https://github.com/Automattic/wp-calypso/pull/98095#discussion_r1937657191 is addressed. | ||
.email-forward-list__actions { | ||
.components-dropdown.components-dropdown-menu { | ||
flex-grow: unset; | ||
} | ||
} |
Oops, something went wrong.