aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/src/components/PersonalInfo/PhoneSection.vue
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings/src/components/PersonalInfo/PhoneSection.vue')
-rw-r--r--apps/settings/src/components/PersonalInfo/PhoneSection.vue53
1 files changed, 53 insertions, 0 deletions
diff --git a/apps/settings/src/components/PersonalInfo/PhoneSection.vue b/apps/settings/src/components/PersonalInfo/PhoneSection.vue
new file mode 100644
index 00000000000..8ddeada960e
--- /dev/null
+++ b/apps/settings/src/components/PersonalInfo/PhoneSection.vue
@@ -0,0 +1,53 @@
+<!--
+ - SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
+ - SPDX-License-Identifier: AGPL-3.0-or-later
+-->
+
+<template>
+ <AccountPropertySection v-bind.sync="phone"
+ :placeholder="t('settings', 'Your phone number')"
+ autocomplete="tel"
+ type="tel"
+ :on-validate="onValidate" />
+</template>
+
+<script>
+import { isValidPhoneNumber } from 'libphonenumber-js'
+import { loadState } from '@nextcloud/initial-state'
+
+import AccountPropertySection from './shared/AccountPropertySection.vue'
+
+import { NAME_READABLE_ENUM } from '../../constants/AccountPropertyConstants.js'
+
+const {
+ defaultPhoneRegion,
+ phone,
+} = loadState('settings', 'personalInfoParameters', {})
+
+export default {
+ name: 'PhoneSection',
+
+ components: {
+ AccountPropertySection,
+ },
+
+ data() {
+ return {
+ phone: { ...phone, readable: NAME_READABLE_ENUM[phone.name] },
+ }
+ },
+
+ methods: {
+ onValidate(value) {
+ if (value === '') {
+ return true
+ }
+
+ if (defaultPhoneRegion) {
+ return isValidPhoneNumber(value, defaultPhoneRegion)
+ }
+ return isValidPhoneNumber(value)
+ },
+ },
+}
+</script>