Skip to content

Commit fa68db1

Browse files
committed
Remake phone number property saving with Vue
Signed-off-by: Christopher Ng <chrng8@gmail.com>
1 parent df757f3 commit fa68db1

File tree

10 files changed

+73
-23
lines changed

10 files changed

+73
-23
lines changed

apps/settings/js/federationsettingsview.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@
130130
field === 'avatar' ||
131131
field === 'email' ||
132132
field === 'displayname' ||
133-
field === 'twitter'
133+
field === 'twitter' ||
134+
field === 'phone'
134135
) {
135136
return;
136137
}

apps/settings/lib/Settings/Personal/PersonalInfo.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ public function getForm(): TemplateResponse {
147147
'federationEnabled' => $federationEnabled,
148148
'lookupServerUploadEnabled' => $lookupServerUploadEnabled,
149149
'avatarScope' => $account->getProperty(IAccountManager::PROPERTY_AVATAR)->getScope(),
150-
'phone' => $account->getProperty(IAccountManager::PROPERTY_PHONE)->getValue(),
151-
'phoneScope' => $account->getProperty(IAccountManager::PROPERTY_PHONE)->getScope(),
152150
'address' => $account->getProperty(IAccountManager::PROPERTY_ADDRESS)->getValue(),
153151
'addressScope' => $account->getProperty(IAccountManager::PROPERTY_ADDRESS)->getScope(),
154152
'website' => $account->getProperty(IAccountManager::PROPERTY_WEBSITE)->getValue(),
@@ -162,6 +160,7 @@ public function getForm(): TemplateResponse {
162160
$personalInfoParameters = [
163161
'userId' => $uid,
164162
'displayName' => $this->getProperty($account, IAccountManager::PROPERTY_DISPLAYNAME),
163+
'phone' => $this->getProperty($account, IAccountManager::PROPERTY_PHONE),
165164
'twitter' => $this->getProperty($account, IAccountManager::PROPERTY_TWITTER),
166165
'emailMap' => $this->getEmailMap($account),
167166
'languageMap' => $this->getLanguageMap($user),
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!--
2+
- @copyright 2022 Christopher Ng <chrng8@gmail.com>
3+
-
4+
- @author Christopher Ng <chrng8@gmail.com>
5+
-
6+
- @license AGPL-3.0-or-later
7+
-
8+
- This program is free software: you can redistribute it and/or modify
9+
- it under the terms of the GNU Affero General Public License as
10+
- published by the Free Software Foundation, either version 3 of the
11+
- License, or (at your option) any later version.
12+
-
13+
- This program is distributed in the hope that it will be useful,
14+
- but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
- GNU Affero General Public License for more details.
17+
-
18+
- You should have received a copy of the GNU Affero General Public License
19+
- along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
-
21+
-->
22+
23+
<template>
24+
<AccountPropertySection v-bind.sync="phone"
25+
:placeholder="t('settings', 'Your phone number')"
26+
type="tel"
27+
:on-validate="onValidate" />
28+
</template>
29+
30+
<script>
31+
import { isValidPhoneNumber } from 'libphonenumber-js'
32+
import { loadState } from '@nextcloud/initial-state'
33+
34+
import AccountPropertySection from './shared/AccountPropertySection.vue'
35+
36+
import { NAME_READABLE_ENUM } from '../../constants/AccountPropertyConstants.js'
37+
38+
const { phone } = loadState('settings', 'personalInfoParameters', {})
39+
40+
export default {
41+
name: 'PhoneSection',
42+
43+
components: {
44+
AccountPropertySection,
45+
},
46+
47+
data() {
48+
return {
49+
phone: { ...phone, readable: NAME_READABLE_ENUM[phone.name] },
50+
}
51+
},
52+
53+
methods: {
54+
onValidate(value) {
55+
return isValidPhoneNumber(value)
56+
},
57+
},
58+
}
59+
</script>

apps/settings/src/main-personal-info.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import '@nextcloud/dialogs/styles/toast.scss'
2828

2929
import DisplayNameSection from './components/PersonalInfo/DisplayNameSection.vue'
3030
import EmailSection from './components/PersonalInfo/EmailSection/EmailSection.vue'
31+
import PhoneSection from './components/PersonalInfo/PhoneSection.vue'
3132
import TwitterSection from './components/PersonalInfo/TwitterSection.vue'
3233
import LanguageSection from './components/PersonalInfo/LanguageSection/LanguageSection.vue'
3334
import ProfileSection from './components/PersonalInfo/ProfileSection/ProfileSection.vue'
@@ -49,11 +50,13 @@ Vue.mixin({
4950

5051
const DisplayNameView = Vue.extend(DisplayNameSection)
5152
const EmailView = Vue.extend(EmailSection)
53+
const PhoneView = Vue.extend(PhoneSection)
5254
const TwitterView = Vue.extend(TwitterSection)
5355
const LanguageView = Vue.extend(LanguageSection)
5456

5557
new DisplayNameView().$mount('#vue-displayname-section')
5658
new EmailView().$mount('#vue-email-section')
59+
new PhoneView().$mount('#vue-phone-section')
5760
new TwitterView().$mount('#vue-twitter-section')
5861
new LanguageView().$mount('#vue-language-section')
5962

apps/settings/templates/settings/personal/personal.info.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,7 @@
120120
<div id="vue-email-section"></div>
121121
</div>
122122
<div class="personal-settings-setting-box">
123-
<form id="phoneform" class="section">
124-
<h3>
125-
<label for="phone"><?php p($l->t('Phone number')); ?></label>
126-
<a href="#" class="federation-menu" aria-label="<?php p($l->t('Change privacy level of phone number')); ?>">
127-
<span class="icon-federation-menu icon-password">
128-
<span class="icon-triangle-s"></span>
129-
</span>
130-
</a>
131-
</h3>
132-
<input type="tel" id="phone" name="phone" value="<?php p($_['phone']) ?>" placeholder="<?php p($l->t('Your phone number')); ?>" autocomplete="on" autocapitalize="none" autocorrect="off" />
133-
<span class="icon-checkmark hidden"></span>
134-
<span class="icon-error hidden"></span>
135-
<input type="hidden" id="phonescope" value="<?php p($_['phoneScope']) ?>">
136-
</form>
123+
<div id="vue-phone-section"></div>
137124
</div>
138125
<div class="personal-settings-setting-box">
139126
<form id="addressform" class="section">

dist/core-common.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-common.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/settings-vue-settings-personal-info.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/settings-vue-settings-personal-info.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"jquery-ui": "^1.13.2",
7171
"jquery-ui-dist": "^1.13.1",
7272
"jstimezonedetect": "^1.0.7",
73+
"libphonenumber-js": "^1.10.11",
7374
"lodash": "^4.17.21",
7475
"marked": "^4.0.14",
7576
"moment": "^2.29.2",

0 commit comments

Comments
 (0)