Skip to content

Commit 37081ae

Browse files
[#19037] feat: new design for manage nickname
1 parent 5fd0b27 commit 37081ae

File tree

5 files changed

+154
-26
lines changed

5 files changed

+154
-26
lines changed

src/status_im/common/validation/profile.cljs

+9
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,12 @@
5050
(has-special-characters? s) (i18n/label :t/are-not-allowed
5151
{:check (i18n/label :t/special-characters)})
5252
(bio-too-long? s) (i18n/label :t/bio-is-too-long)))
53+
54+
(defn validation-nickname
55+
[s]
56+
(cond
57+
(or (= s nil) (= s "")) nil
58+
(has-emojis? s) (i18n/label :t/are-not-allowed {:check (i18n/label :t/emojis)})
59+
(has-special-characters? s) (i18n/label :t/are-not-allowed
60+
{:check (i18n/label :t/special-characters)})
61+
(name-too-long? s) (i18n/label :t/nickname-is-too-long)))
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,58 @@
11
(ns status-im.contexts.profile.contact.actions.view
2-
(:require [quo.core :as quo]
2+
(:require [clojure.string :as string]
3+
[quo.core :as quo]
4+
[react-native.core :as rn]
35
[status-im.common.not-implemented :as not-implemented]
4-
[utils.i18n :as i18n]))
6+
[status-im.contexts.profile.contact.add-nickname.view :as add-nickname]
7+
[utils.i18n :as i18n]
8+
[utils.re-frame :as rf]))
59

610
(defn view
711
[]
8-
[quo/action-drawer
9-
[[{:icon :i/edit
10-
:label (i18n/label :t/add-nickname-title)
11-
:on-press not-implemented/alert
12-
:accessibility-label :add-nickname}
13-
{:icon :i/qr-code
14-
:label (i18n/label :t/show-qr)
15-
:on-press not-implemented/alert
16-
:accessibility-label :show-qr-code}
17-
{:icon :i/share
18-
:label (i18n/label :t/share-profile)
19-
:on-press not-implemented/alert
20-
:accessibility-label :share-profile}
21-
{:icon :i/untrustworthy
22-
:label (i18n/label :t/mark-untrustworthy)
23-
:on-press not-implemented/alert
24-
:accessibility-label :mark-untrustworthy
25-
:add-divider? true
26-
:danger? true}
27-
{:icon :i/block
28-
:label (i18n/label :t/block-user)
29-
:on-press not-implemented/alert
30-
:accessibility-label :block-user
31-
:danger? true}]]])
12+
(let [{:keys [nickname public-key]} (rf/sub [:contacts/current-contact])
13+
on-add-nickname (rn/use-callback #(rf/dispatch [:show-bottom-sheet
14+
{:content
15+
(fn [] [add-nickname/view])}]))
16+
on-remove-nickname (rn/use-callback
17+
(fn []
18+
(rf/dispatch [:hide-bottom-sheet])
19+
(rf/dispatch [:toasts/upsert
20+
{:id :remove-nickname
21+
:type :positive
22+
:text (i18n/label :t/nickname-removed)}])
23+
(rf/dispatch [:contacts/update-nickname public-key ""]))
24+
[public-key])
25+
has-nickname? (rn/use-memo (fn [] (not (string/blank? nickname))) [nickname])]
26+
[quo/action-drawer
27+
[[{:icon :i/edit
28+
:label (if has-nickname?
29+
(i18n/label :t/edit-nickname)
30+
(i18n/label :t/add-nickname-title))
31+
:on-press on-add-nickname
32+
:accessibility-label (if nickname :edit-nickname :add-nickname)}
33+
{:icon :i/qr-code
34+
:label (i18n/label :t/show-qr)
35+
:on-press not-implemented/alert
36+
:accessibility-label :show-qr-code}
37+
{:icon :i/share
38+
:label (i18n/label :t/share-profile)
39+
:on-press not-implemented/alert
40+
:accessibility-label :share-profile}
41+
(when has-nickname?
42+
{:icon :i/delete
43+
:label (i18n/label :t/remove-nickname)
44+
:on-press on-remove-nickname
45+
:add-divider? true
46+
:accessibility-label :remove-nickname
47+
:danger? true})
48+
{:icon :i/untrustworthy
49+
:label (i18n/label :t/mark-untrustworthy)
50+
:on-press not-implemented/alert
51+
:accessibility-label :mark-untrustworthy
52+
:add-divider? (when (not has-nickname?) true)
53+
:danger? true}
54+
{:icon :i/block
55+
:label (i18n/label :t/block-user)
56+
:on-press not-implemented/alert
57+
:accessibility-label :block-user
58+
:danger? true}]]]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(ns status-im.contexts.profile.contact.add-nickname.style)
2+
3+
(def input-wrapper
4+
{:padding-vertical 8
5+
:padding-horizontal 20
6+
:gap 8})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
(ns status-im.contexts.profile.contact.add-nickname.view
2+
(:require [clojure.string :as string]
3+
[quo.components.info.info-message :as info-message]
4+
[quo.core :as quo]
5+
[react-native.core :as rn]
6+
[status-im.common.validation.profile :as profile-validator]
7+
[status-im.constants :as constants]
8+
[status-im.contexts.profile.contact.add-nickname.style :as style]
9+
[status-im.contexts.profile.utils :as profile.utils]
10+
[utils.debounce :as debounce]
11+
[utils.i18n :as i18n]
12+
[utils.re-frame :as rf]))
13+
14+
(defn view
15+
[]
16+
(let [{:keys [public-key primary-name nickname customization-color]
17+
:as profile} (rf/sub [:contacts/current-contact])
18+
;; TODO: remove :blue when #18733 merged.
19+
customization-color (or customization-color :blue)
20+
full-name (profile.utils/displayed-name profile)
21+
profile-picture (profile.utils/photo profile)
22+
[unsaved-nickname set-unsaved-nickname] (rn/use-state nickname)
23+
[error-msg set-error-msg] (rn/use-state nil)
24+
validate-nickname (rn/use-callback
25+
(debounce/debounce
26+
(fn [name]
27+
(set-error-msg
28+
(profile-validator/validation-nickname name)))
29+
300))
30+
on-cancel (rn/use-callback #(rf/dispatch [:hide-bottom-sheet]))
31+
on-nickname-change (rn/use-callback (fn [text]
32+
(set-unsaved-nickname text)
33+
(validate-nickname text)))
34+
on-nickname-submit (rn/use-callback
35+
(fn []
36+
(rf/dispatch [:hide-bottom-sheet])
37+
(rf/dispatch [:toasts/upsert
38+
{:id :add-nickname
39+
:type :positive
40+
:text (i18n/label
41+
(if (string/blank? nickname)
42+
:t/nickname-added
43+
:t/nickname-updated)
44+
{:primary-name primary-name})}])
45+
(rf/dispatch [:contacts/update-nickname public-key
46+
(string/trim unsaved-nickname)]))
47+
[public-key unsaved-nickname])]
48+
[:<>
49+
[quo/drawer-top
50+
{:type :context-tag
51+
:context-tag-type :default
52+
:title (i18n/label :t/add-nickname-title)
53+
:full-name full-name
54+
:profile-picture profile-picture
55+
:customization-color customization-color}]
56+
[rn/view {:style style/input-wrapper}
57+
[quo/input
58+
{:type :text
59+
:char-limit constants/profile-name-max-length
60+
:max-length constants/profile-name-max-length
61+
:auto-focus true
62+
:default-value unsaved-nickname
63+
:error? (not (string/blank? error-msg))
64+
:label (i18n/label :t/nickname)
65+
:on-change-text on-nickname-change}
66+
:on-submit-editing on-nickname-submit]
67+
[info-message/info-message
68+
{:icon :i/info
69+
:size :default
70+
:type (if (not (string/blank? error-msg)) :error :default)}
71+
(if (not (string/blank? error-msg))
72+
error-msg
73+
(i18n/label :t/nickname-visible-to-you))]]
74+
[quo/bottom-actions
75+
{:actions :two-actions
76+
:button-one-label (i18n/label :t/add-nickname-title)
77+
:button-one-props {:disabled? (or (string/blank? unsaved-nickname)
78+
(not (string/blank? error-msg)))
79+
:on-press on-nickname-submit}
80+
:button-two-label (i18n/label :t/cancel)
81+
:button-two-props {:type :grey
82+
:on-press on-cancel}}]]))

translations/en.json

+4
Original file line numberDiff line numberDiff line change
@@ -1652,12 +1652,16 @@
16521652
"page-would-like-to-use-camera": "would like to use your camera",
16531653
"page-camera-request-blocked": "camera requests blocked. To enable camera requests go to Settings",
16541654
"nickname": "Nickname",
1655+
"nickname-is-too-long": "Nickname is too long",
16551656
"add-nickname": "Add a nickname (optional)",
16561657
"edit-nickname": "Edit nickname",
16571658
"add-nickname-title": "Add nickname",
16581659
"nickname-visible-to-you": "Nickname will only be visible to you",
16591660
"type-nickname": "Type nickname",
16601661
"remove-nickname": "Remove nickname",
1662+
"nickname-removed": "Nickname removed",
1663+
"nickname-added": "Nickname for {{primary-name}} added",
1664+
"nickname-updated": "Nickname for {{primary-name}} updated",
16611665
"set-nickname-toast": "You have renamed {{primary-name}} as {{nickname}}",
16621666
"remove-nickname-toast": "You have removed {{secondary-name}}'s nickname",
16631667
"nickname-description": "Nicknames help you identify others in Status.\nOnly you can see the nicknames you’ve added",

0 commit comments

Comments
 (0)