Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
363 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,51 @@ | ||
(ns sb.app.domain-name.ui | ||
(:require [clojure.string :as str] | ||
[inside-out.forms :as forms] | ||
(:require [inside-out.forms :as io] | ||
[promesa.core :as p] | ||
[sb.app.domain-name.data :as data] | ||
[sb.app.field.ui :as field.ui] | ||
[sb.app.form.ui :as form.ui] | ||
[sb.app.views.ui :as ui] | ||
[sb.i18n :refer [t]])) | ||
[sb.i18n :refer [t]] | ||
[sb.util :as u])) | ||
|
||
#?(:cljs | ||
(defn availability-validator [] | ||
(-> (fn [v {:keys [field]}] | ||
(when (not= (:domain-name/name (:init field)) | ||
(:domain-name/name v)) | ||
(when-let [v (:domain-name/name v)] | ||
(when (>= (count v) 3) | ||
(p/let [res (data/check-availability {:domain v})] | ||
(if (:available? res) | ||
(forms/message :info | ||
[:span.text-green-500.font-bold (t :tr/available)]) | ||
(forms/message :invalid | ||
(t :tr/not-available) | ||
{:visibility :always}))))))) | ||
(forms/debounce 300)))) | ||
(-> (fn [v {:as what :keys [field]}] | ||
(when (and v | ||
(not= v (:init field)) | ||
(>= (count v) 3)) | ||
(p/let [res (data/check-availability {:domain v})] | ||
(prn :res res) | ||
(if (:available? res) | ||
(io/message :info | ||
[:span.text-green-500.font-bold (t :tr/available)]) | ||
(io/message :invalid | ||
(t :tr/not-available) | ||
{:visibility :always}))))) | ||
(io/debounce 300)))) | ||
|
||
|
||
(ui/defview domain-field [?domain props] | ||
(defn make-domain-field [init _props] | ||
(io/form {:domain-name/name | ||
(some-> domain-name/?name | ||
u/some-str | ||
data/normalize-domain | ||
data/qualify-domain)} | ||
:meta {domain-name/?name {:init (or (some-> init | ||
:domain-name/name | ||
data/unqualify-domain) | ||
"") | ||
:validators [data/domain-valid-string | ||
#?(:cljs (availability-validator))]}} | ||
)) | ||
|
||
(ui/defview domain-field [{:as ?field :syms [domain-name/?name]} props] | ||
[:div.field-wrapper | ||
[form.ui/show-label ?domain] | ||
[form.ui/show-label ?field (:field/label props)] | ||
[:div.flex.gap-2.items-stretch | ||
(field.ui/text-field ?domain (merge props | ||
{:wrap (fn [v] | ||
(when-not (str/blank? v) | ||
{:domain-name/name (data/qualify-domain (data/normalize-domain v))})) | ||
:unwrap (fn [v] | ||
(or (some-> v :domain-name/name data/unqualify-domain) "")) | ||
:auto-complete "off" | ||
:spell-check false | ||
:wrapper-class "flex-auto" | ||
:label false})) | ||
[:div.flex.items-center.text-sm.text-gray-500.h-10 ".sparkboard.com"]]]) | ||
|
||
(defn validators [] | ||
[data/domain-valid-string | ||
#?(:cljs (availability-validator))]) | ||
(field.ui/text-field ?name (merge props | ||
{:auto-complete "off" | ||
:spell-check false | ||
:field/wrapper-class "flex-auto" | ||
:field/label false})) | ||
[:div.flex.items-center.text-sm.text-gray-500.h-10 ".sparkboard.com"]]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.