|
28 | 28 |
|
29 | 29 | (defn password-inputs |
30 | 30 | [{:keys [set-password set-repeat-password same-password-length? same-passwords? |
31 | | - password-long-enough? password-short-enough? non-empty-password?]}] |
32 | | - (let [[show-validation? |
33 | | - set-show-validation?] (rn/use-state false) |
34 | | - on-change-password (rn/use-callback |
35 | | - (fn [new-value] |
36 | | - (set-password new-value) |
37 | | - (when same-password-length? |
38 | | - (set-show-validation? true))) |
39 | | - [same-password-length?]) |
40 | | - on-change-repeat-password (rn/use-callback |
41 | | - (fn [new-value] |
42 | | - (set-repeat-password new-value) |
43 | | - (when same-password-length? |
44 | | - (set-show-validation? true))) |
45 | | - [same-password-length?]) |
46 | | - on-blur-repeat-password (rn/use-callback |
47 | | - #(set-show-validation? non-empty-password?) |
48 | | - [non-empty-password?]) |
49 | | - hint-1-status (if password-long-enough? :success :default) |
50 | | - hint-2-status (if same-passwords? :success :error) |
51 | | - hint-2-text (if same-passwords? |
52 | | - (i18n/label :t/password-creation-match) |
53 | | - (i18n/label :t/password-creation-dont-match)) |
54 | | - error? (and show-validation? |
55 | | - (not same-passwords?) |
56 | | - non-empty-password?)] |
| 31 | + password-long-enough? password-short-enough?]}] |
| 32 | + (let [hint-1-status (if password-long-enough? :success :default) |
| 33 | + hint-2-status (if same-passwords? :success :error) |
| 34 | + hint-2-text (if same-passwords? |
| 35 | + (i18n/label :t/password-creation-match) |
| 36 | + (i18n/label :t/password-creation-dont-match)) |
| 37 | + [error? set-error] (rn/use-state false)] |
| 38 | + (rn/use-effect |
| 39 | + (fn [] |
| 40 | + (when (and (not error?) same-password-length? (not same-passwords?)) |
| 41 | + (set-error true))) |
| 42 | + [error? same-password-length? same-passwords?]) |
57 | 43 | [:<> |
58 | 44 | [password-with-hint/view |
59 | 45 | {:hint (if (not password-short-enough?) |
|
64 | 50 | :status hint-1-status |
65 | 51 | :shown? true}) |
66 | 52 | :placeholder (i18n/label :t/password-creation-placeholder-1) |
67 | | - :on-change-text on-change-password |
| 53 | + :on-change-text set-password |
68 | 54 | :auto-focus true}] |
69 | 55 | [rn/view {:style style/space-between-inputs}] |
70 | 56 | [password-with-hint/view |
71 | 57 | {:hint {:text hint-2-text |
72 | 58 | :status hint-2-status |
73 | | - :shown? (and non-empty-password? show-validation?)} |
74 | | - :error? error? |
| 59 | + :shown? (or same-passwords? error?)} |
| 60 | + :error? (and error? (not same-passwords?)) |
75 | 61 | :placeholder (i18n/label :t/password-creation-placeholder-2) |
76 | | - :on-change-text on-change-repeat-password |
77 | | - :on-blur on-blur-repeat-password}]])) |
| 62 | + :on-change-text set-repeat-password}]])) |
78 | 63 |
|
79 | 64 | (defn help |
80 | 65 | [{:keys [lower-case? upper-case? numbers? symbols?] :as validations}] |
|
0 commit comments