From d97bb764aaf13d4c63aad11d33e3e45b64d35ecd Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 18 Nov 2019 17:37:38 +0100 Subject: [PATCH] Close #311 and refactor identity edition pages with a mixin Signed-off-by: Thomas Citharel --- js/src/mixins/identityEdition.ts | 35 +++++++++++++ js/src/views/Account/Register.vue | 26 +++++----- .../views/Account/children/EditIdentity.vue | 49 +++++++------------ 3 files changed, 66 insertions(+), 44 deletions(-) create mode 100644 js/src/mixins/identityEdition.ts diff --git a/js/src/mixins/identityEdition.ts b/js/src/mixins/identityEdition.ts new file mode 100644 index 000000000..d4f54f862 --- /dev/null +++ b/js/src/mixins/identityEdition.ts @@ -0,0 +1,35 @@ +import { Component, Mixins, Vue } from 'vue-property-decorator'; +import { Person } from '@/types/actor'; + +@Component +export default class IdentityEditionMixin extends Mixins(Vue) { + + identity = new Person(); + oldDisplayName: string | null = null; + + autoUpdateUsername(newDisplayName: string | null) { + const oldUsername = IdentityEditionMixin.convertToUsername(this.oldDisplayName); + + if (this.identity.preferredUsername === oldUsername) { + this.identity.preferredUsername = IdentityEditionMixin.convertToUsername(newDisplayName); + } + + this.oldDisplayName = newDisplayName; + } + + private static convertToUsername(value: string | null) { + if (!value) return ''; + + // https://stackoverflow.com/a/37511463 + return value.toLocaleLowerCase() + .normalize('NFD') + .replace(/[\u0300-\u036f]/g, '') + .replace(/ /g, '_') + .replace(/[^a-z0-9_]/g, '') + ; + } + + validateUsername() { + return this.identity.preferredUsername === IdentityEditionMixin.convertToUsername(this.identity.preferredUsername); + } +} diff --git a/js/src/views/Account/Register.vue b/js/src/views/Account/Register.vue index d4b23a775..468d9c262 100644 --- a/js/src/views/Account/Register.vue +++ b/js/src/views/Account/Register.vue @@ -9,6 +9,10 @@ {{ $t('To achieve your registration, please create a first identity profile.')}}
+ + + +

@{{ host }} @@ -27,12 +31,8 @@ - - - - - +

@@ -45,7 +45,7 @@

- {{ $t('Your account is nearly ready, {username}', { username: person.preferredUsername }) }} + {{ $t('Your account is nearly ready, {username}', { username: identity.preferredUsername }) }}

{{ $t('A validation email was sent to {email}', { email }) }} @@ -61,22 +61,22 @@