Skip to content

Commit

Permalink
feat: change button flow. Add validations and make it responsive (#367)
Browse files Browse the repository at this point in the history
* feat: UserMenu Update. and other validations

* style: responsive

* feat: change send email button flow

* test: saveSubscriptionEmailSuccess

* refactor: SpanUnconfirmedEmail

BREAKING CHANGE: rename functions in UserMenu props in decentraland-ui
  • Loading branch information
braianj authored May 23, 2024
1 parent ebe4e22 commit 880c56b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback, useEffect, useMemo, useState } from 'react'
import { useHistory } from 'react-router-dom'
import { Email } from '@dcl/schemas'
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
import { objectToSnake } from 'ts-case-convert'
Expand Down Expand Up @@ -28,6 +29,7 @@ function NotificationEmailCard(props: Props) {
} = props
const [isValidEmail, setIsValidEmail] = useState(true)
const [email, setEmail] = useState(unconfirmedEmail || emailProp)
const history = useHistory()

useEffect(() => {
if (unconfirmedEmail || emailProp) {
Expand All @@ -47,6 +49,7 @@ function NotificationEmailCard(props: Props) {
const handleOnChangeEmail = useCallback(
(event: React.ChangeEvent<HTMLInputElement>) => {
setEmail(event.target.value)
history.replace({ state: {} })
},
[setEmail]
)
Expand Down Expand Up @@ -78,11 +81,11 @@ function NotificationEmailCard(props: Props) {
const buttonText = useMemo(() => {
if (!emailProp && !unconfirmedEmail && !hasConfirmEmail) {
return t('settings.notifications.email.button_submit_label')
} else if (unconfirmedEmail) {
} else if (unconfirmedEmail && unconfirmedEmail === email) {
return t('settings.notifications.email.button_resend_label')
}
return t('settings.notifications.email.button_edit_label')
}, [emailProp, unconfirmedEmail, hasConfirmEmail])
}, [emailProp, unconfirmedEmail, hasConfirmEmail, email])

return (
<>
Expand All @@ -91,8 +94,11 @@ function NotificationEmailCard(props: Props) {
<Title variant="h6" data-testid={NOTIFICATION_EMAIL_CARD_TITLE_TEST_ID}>
{t('settings.notifications.email.title')}

{(unconfirmedEmail || hasConfirmEmail) && (
<SpanUnconfirmedEmail confirmed={hasConfirmEmail} data-testid={NOTIFICATION_EMAIL_CARD_UNCONFIRMED_TEST_ID}>
{(hasConfirmEmail || unconfirmedEmail) && (
<SpanUnconfirmedEmail
confirmed={hasConfirmEmail && !unconfirmedEmail}
data-testid={NOTIFICATION_EMAIL_CARD_UNCONFIRMED_TEST_ID}
>
{hasConfirmEmail ? t('settings.notifications.email.confirmed') : t('settings.notifications.email.pending_approval')}
</SpanUnconfirmedEmail>
)}
Expand Down Expand Up @@ -121,7 +127,7 @@ function NotificationEmailCard(props: Props) {
<Button
variant="contained"
onClick={handleSaveEmail}
disabled={isLoading || email === emailProp}
disabled={isLoading || (email === emailProp && !unconfirmedEmail)}
data-testid={NOTIFICATION_EMAIL_CARD_BUTTON_TEST_ID}
>
{isLoading ? <CircularProgress size={20} data-testid={NOTIFICATION_EMAIL_CARD_BUTTON_LOADING_TEST_ID} /> : buttonText}
Expand Down
7 changes: 7 additions & 0 deletions src/components/Wallets/AccountCard/AccountCard.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@
opacity: 0;
cursor: pointer;
}

@media (max-width: 768px) {
.AccountCard.ui.card {
min-width: auto;
margin: 0 0 12px 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@
padding-left: 50px;
}
}
@media (max-width: 768px) {
.AccountCardContainer {
padding: 0;
}
}
19 changes: 19 additions & 0 deletions src/modules/subscription/reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,25 @@ describe('when reducing the update of the email subscription success action', ()
error: null
})
})

describe('and there is an unconfirmed email and the user set to confirm the same email and the already validated before', () => {
beforeEach(() => {
state = {
...state,
email: subscription.email!,
unconfirmedEmail,
loading: [saveSubscriptionEmailRequest(unconfirmedEmail)]
}
})
it('should return a state with the unconfirmed email undefined and the loading state cleared', () => {
expect(subscriptionReducer(state, saveSubscriptionEmailSuccess(state.email))).toEqual({
...state,
unconfirmedEmail: undefined,
loading: [],
error: null
})
})
})
})

describe('when reducing update of the email subscription failure action', () => {
Expand Down
7 changes: 5 additions & 2 deletions src/modules/subscription/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,13 @@ export function subscriptionReducer(state = buildInitialState(), action: Subscri

case SAVE_SUBSCRIPTION_EMAIL_SUCCESS: {
const { email } = action.payload

let unconfirmedEmail: string | undefined = email
if (state.email === email) {
unconfirmedEmail = undefined
}
return {
...state,
unconfirmedEmail: email,
unconfirmedEmail,
loading: loadingReducer(state.loading, action)
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/modules/subscription/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export const subscriptionGroups: SubscriptionGroups = {
[SubscriptionGroupKeys.WORLDS]: [
NotificationType.WORLDS_ACCESS_RESTORED,
NotificationType.WORLDS_ACCESS_RESTRICTED,
NotificationType.WORLDS_MISSING_RESOURCES
NotificationType.WORLDS_MISSING_RESOURCES,
NotificationType.WORLDS_PERMISSION_GRANTED,
NotificationType.WORLDS_PERMISSION_REVOKED
]
}

Expand Down

0 comments on commit 880c56b

Please sign in to comment.