Skip to content

fix: Use nextcloud-vue components for personal info settings #43488

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

Merged
merged 4 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default {
flex-direction: column;
margin: 10px 32px 10px 0;
gap: 16px 0;
color: var(--color-text-lighter);
color: var(--color-text-maxcontrast);

&__groups,
&__quota {
Expand All @@ -117,7 +117,7 @@ export default {
font-weight: bold;
}

&::v-deep .material-design-icon {
&:deep(.material-design-icon) {
align-self: flex-start;
margin-top: 2px;
}
Expand Down
251 changes: 115 additions & 136 deletions apps/settings/src/components/PersonalInfo/EmailSection/Email.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,63 +23,69 @@
<template>
<div>
<div class="email">
<input :id="inputIdWithDefault"
<NcInputField :id="inputIdWithDefault"
ref="email"
type="email"
autocapitalize="none"
autocomplete="email"
:aria-label="inputPlaceholder"
:error="hasError || !!helperText"
:helper-text="helperText || undefined"
:label="inputPlaceholder"
:placeholder="inputPlaceholder"
:value="email"
:aria-describedby="helperText ? `${inputIdWithDefault}-helper-text` : undefined"
autocapitalize="none"
spellcheck="false"
@input="onEmailChange">

<div class="email__actions-container">
<transition name="fade">
<Check v-if="showCheckmarkIcon" :size="20" />
<AlertOctagon v-else-if="showErrorIcon" :size="20" />
</transition>

<template v-if="!primary">
<FederationControl :readable="propertyReadable"
:additional="true"
:additional-value="email"
:disabled="federationDisabled"
:handle-additional-scope-change="saveAdditionalEmailScope"
:scope.sync="localScope"
@update:scope="onScopeChange" />
</template>

<NcActions class="email__actions"
:aria-label="t('settings', 'Email options')"
:force-menu="true">
<NcActionButton :aria-label="deleteEmailLabel"
:close-after-click="true"
:disabled="deleteDisabled"
icon="icon-delete"
@click.stop.prevent="deleteEmail">
{{ deleteEmailLabel }}
</NcActionButton>
<NcActionButton v-if="!primary || !isNotificationEmail"
:aria-label="setNotificationMailLabel"
:close-after-click="true"
:disabled="setNotificationMailDisabled"
icon="icon-favorite"
@click.stop.prevent="setNotificationMail">
{{ setNotificationMailLabel }}
</NcActionButton>
:success="isSuccess"
type="email"
:value.sync="emailAddress" />

<div class="email__actions">
<NcActions :aria-label="actionsLabel" @close="showFederationSettings = false">
<template v-if="showFederationSettings">
<NcActionButton @click="showFederationSettings = false">
Comment on lines +40 to +42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Isn't the latter @click redundant, due to the parent NcActions having the same effect on close? It can be removed, because the action gets done twice whenever the button is clicked to close.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No thats two different actions as this is a "submenu".
This one (the button click) is to allow the user to go back in the menu. The close event is to reset the menu to the main menu on close.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. My bad!

<template #icon>
<NcIconSvgWrapper :path="mdiArrowLeft" />
</template>
{{ t('settings', 'Back') }}
</NcActionButton>
<FederationControlActions :readable="propertyReadable"
:additional="true"
:additional-value="email"
:disabled="federationDisabled"
:handle-additional-scope-change="saveAdditionalEmailScope"
:scope.sync="localScope"
@update:scope="onScopeChange" />
</template>
<template v-else>
<NcActionButton v-if="!federationDisabled && !primary"
@click="showFederationSettings = true">
<template #icon>
<NcIconSvgWrapper :path="mdiLock" />
</template>
{{ t('settings', 'Change scope level of {property}', { property: propertyReadable.toLocaleLowerCase() }) }}
</NcActionButton>
<NcActionCaption v-if="!isConfirmedAddress"
:name="t('settings', 'This address is not confirmed')" />
<NcActionButton close-after-click
:disabled="deleteDisabled"
@click="deleteEmail">
<template #icon>
<NcIconSvgWrapper :path="mdiTrashCan" />
</template>
{{ deleteEmailLabel }}
</NcActionButton>
<NcActionButton v-if="!primary || !isNotificationEmail"
close-after-click
:disabled="!isConfirmedAddress"
@click="setNotificationMail">
<template #icon>
<NcIconSvgWrapper v-if="isNotificationEmail" :path="mdiStar" />
<NcIconSvgWrapper v-else :path="mdiStarOutline" />
</template>
{{ setNotificationMailLabel }}
</NcActionButton>
</template>
</NcActions>
</div>
</div>

<p v-if="helperText"
:id="`${inputIdWithDefault}-helper-text`"
class="email__helper-text-message email__helper-text-message--error">
<AlertCircle class="email__helper-text-message__icon" :size="18" />
{{ helperText }}
</p>

<em v-if="isNotificationEmail">
{{ t('settings', 'Primary email for password reset and notifications') }}
</em>
Expand All @@ -89,12 +95,13 @@
<script>
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import AlertCircle from 'vue-material-design-icons/AlertCircleOutline.vue'
import AlertOctagon from 'vue-material-design-icons/AlertOctagon.vue'
import Check from 'vue-material-design-icons/Check.vue'
import NcActionCaption from '@nextcloud/vue/dist/Components/NcActionCaption.js'
import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js'
import NcInputField from '@nextcloud/vue/dist/Components/NcInputField.js'
import debounce from 'debounce'

import FederationControl from '../shared/FederationControl.vue'
import { mdiArrowLeft, mdiLock, mdiStar, mdiStarOutline, mdiTrashCan } from '@mdi/js'
import FederationControlActions from '../shared/FederationControlActions.vue'
import { handleError } from '../../../utils/handlers.js'

import { ACCOUNT_PROPERTY_READABLE_ENUM, VERIFICATION_ENUM } from '../../../constants/AccountPropertyConstants.js'
Expand All @@ -114,10 +121,10 @@ export default {
components: {
NcActions,
NcActionButton,
AlertCircle,
AlertOctagon,
Check,
FederationControl,
NcActionCaption,
NcIconSvgWrapper,
NcInputField,
FederationControlActions,
},

props: {
Expand Down Expand Up @@ -152,19 +159,38 @@ export default {
},
},

setup() {
return {
mdiArrowLeft,
mdiLock,
mdiStar,
mdiStarOutline,
mdiTrashCan,
saveAdditionalEmailScope,
}
},

data() {
return {
propertyReadable: ACCOUNT_PROPERTY_READABLE_ENUM.EMAIL,
hasError: false,
helperText: null,
initialEmail: this.email,
isSuccess: false,
localScope: this.scope,
saveAdditionalEmailScope,
helperText: null,
showCheckmarkIcon: false,
showErrorIcon: false,
propertyReadable: ACCOUNT_PROPERTY_READABLE_ENUM.EMAIL,
showFederationSettings: false,
}
},

computed: {
actionsLabel() {
if (this.primary) {
return t('settings', 'Email options')
} else {
return t('settings', 'Options for additional email address {index}', { index: this.index + 1 })
}
},

deleteDisabled() {
if (this.primary) {
// Disable for empty primary email as there is nothing to delete
Expand All @@ -183,15 +209,13 @@ export default {
return t('settings', 'Delete email')
},

setNotificationMailDisabled() {
return !this.primary && this.localVerificationState !== VERIFICATION_ENUM.VERIFIED
isConfirmedAddress() {
return this.primary || this.localVerificationState === VERIFICATION_ENUM.VERIFIED
},

setNotificationMailLabel() {
setNotificationMailLabel() {
if (this.isNotificationEmail) {
return t('settings', 'Unset as primary email')
} else if (!this.primary && this.localVerificationState !== VERIFICATION_ENUM.VERIFIED) {
return t('settings', 'This address is not confirmed')
}
return t('settings', 'Set as primary email')
},
Expand All @@ -213,25 +237,30 @@ export default {
return (this.email && this.email === this.activeNotificationEmail)
|| (this.primary && this.activeNotificationEmail === '')
},

emailAddress: {
get() {
return this.email
},
set(value) {
this.$emit('update:email', value)
this.debounceEmailChange(value.trim())
},
},
},

mounted() {
if (!this.primary && this.initialEmail === '') {
// $nextTick is needed here, otherwise it may not always work https://stackoverflow.com/questions/51922767/autofocus-input-on-mount-vue-ios/63485725#63485725
// $nextTick is needed here, otherwise it may not always work
// https://stackoverflow.com/questions/51922767/autofocus-input-on-mount-vue-ios/63485725#63485725
this.$nextTick(() => this.$refs.email?.focus())
}
},

methods: {
onEmailChange(e) {
this.$emit('update:email', e.target.value)
this.debounceEmailChange(e.target.value.trim())
},

debounceEmailChange: debounce(async function(email) {
this.helperText = null
if (this.$refs.email?.validationMessage) {
this.helperText = this.$refs.email.validationMessage
this.helperText = this.$refs.email?.$refs.input?.validationMessage || null
if (this.helperText !== null) {
return
}
if (validateEmail(email) || email === '') {
Expand Down Expand Up @@ -356,12 +385,12 @@ export default {
} else if (notificationEmail !== undefined) {
this.$emit('update:notification-email', notificationEmail)
}
this.showCheckmarkIcon = true
setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
this.isSuccess = true
setTimeout(() => { this.isSuccess = false }, 2000)
} else {
handleError(error, errorMessage)
this.showErrorIcon = true
setTimeout(() => { this.showErrorIcon = false }, 2000)
this.hasError = true
setTimeout(() => { this.hasError = false }, 2000)
}
},

Expand All @@ -374,66 +403,16 @@ export default {

<style lang="scss" scoped>
.email {
display: grid;
align-items: center;

input {
grid-area: 1 / 1;
width: 100%;
}

.email__actions-container {
grid-area: 1 / 1;
justify-self: flex-end;
height: 30px;
display: flex;
flex-direction: row;
align-items: start;
gap: 4px;

&__actions {
display: flex;
gap: 0 2px;
margin-right: 5px;

.email__actions {
&:hover,
&:focus,
&:active {
opacity: 0.8 !important;
}

&::v-deep button {
height: 30px !important;
min-height: 30px !important;
width: 30px !important;
min-width: 30px !important;
}
}
}

&__helper-text-message {
padding: 4px 0;
display: flex;
align-items: center;

&__icon {
margin-right: 8px;
align-self: start;
margin-top: 4px;
}

&--error {
color: var(--color-error);
}
margin-top: 6px;
}
}

.fade-enter,
.fade-leave-to {
opacity: 0;
}

.fade-enter-active {
transition: opacity 200ms ease-out;
}

.fade-leave-active {
transition: opacity 300ms ease-out;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@ export default {
section {
padding: 10px 10px;

&::v-deep button:disabled {
cursor: default;
}

.additional-emails-label {
display: block;
margin-top: 16px;
Expand Down
Loading