Skip to content

Instantly share code, notes, and snippets.

@njj

njj/blah.cljs Secret

Created May 31, 2019 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njj/7f69294fe8ce81c6ab6ab63a06af5051 to your computer and use it in GitHub Desktop.
Save njj/7f69294fe8ce81c6ab6ab63a06af5051 to your computer and use it in GitHub Desktop.
(defsc Price [this {:keys [value type] :as props} {:keys [edit-mode?]}]
{:query [:_id
:value
:type
:currency
fs/form-config-join]
:form-fields #{:value}
:ident [:prices/by-id :_id]}
(dom/div
(condp = type
"HOURLY_RATE"
(dom/div
:.form-group.mb-0
(dom/label
:.col-sm-4.control-label "Hourly price")
(dom/div
:.col-sm-8
(if-not edit-mode?
(dom/p
:.form-control-static value)
(dom/input
:.form-control
{:type "text"
:value value
:onChange #(m/set-string! this :value :event %)
:onBlur #(js/console.log (fs/dirty-fields props true))})))))))
(def ui-price (prim/factory Price {:keyfn :_id}))
(defsc ListingForm
[this {:keys [ui/edit-mode? prices _id] :as props} {:keys []}]
{:query [:_id
{:prices (prim/get-query Price)}
:ui/edit-mode?
fs/form-config-join]
:form-fields #{:prices}
:ident [:listing/by-id :_id]
:initial-state {:ui/edit-mode? "listing-details"}}
(let [listing-edit? (= edit-mode? "listing-details")
entity-ident (prim/get-ident this (prim/props this))]
(dom/div
(dom/p :.title "Listing Details")
(dom/form
:.form-horizontal
(dom/div
:.row
(dom/div
:.col-md-6
(mapv (fn [p] (ui-price (prim/computed p {:edit-mode? listing-edit?}))) prices)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment