Skip to content

Instantly share code, notes, and snippets.

@awkay

awkay/form.cljs Secret

Forked from njj/form.cljs
Last active February 21, 2019 19:53
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 awkay/07f32eea0df183d4bea4c5f597c0ce8e to your computer and use it in GitHub Desktop.
Save awkay/07f32eea0df183d4bea4c5f597c0ce8e to your computer and use it in GitHub Desktop.
(defn my-form-ident [{:keys [booking]}]
[:booking/id (:id booking)])
(defsc Step1Form [this props]
{:query (fn [] ['* fs/form-config-join]) ; doesn't matter, since it isn't really used
:ident (fn [] (my-form-ident props))}
(dom/div "Step 1"))
(def ui-step1-form (prim/factory Step1Form))
(defsc Step2Form [this props]
{:query (fn [] ['* fs/form-config-join]) ; doesn't matter, since it isn't really used
:ident (fn [] (my-form-ident props))}
(dom/div "Step 2"))
(def ui-step2-form (prim/factory Step2Form))
(defsc BookingForm [this props {:keys [step]}]
{:query [:cleaning-fee :total fs/form-config-join]
:form-fields #{:cleaning-fee :total}
:ident (fn [] (my-form-ident props))}
(case step
1 (ui-step1-form props)
2 (ui-step2-form props)))
(def ui-booking-form (prim/factory BookingForm))
(defmutation next-step [{:keys [step]}]
(action [{:keys [state]}]
(js/console.log state)
(swap! state update-in [:COMPONENT/by-id :wrapper :ui/step] inc)))
(defsc FormProto [this {:keys [ui/step booking] :as props}]
{:query [:ui/step
{:booking (prim/get-query BookingForm)}
[:web-env '_]]
:ident (fn [] [:COMPONENT/by-id :wrapper])
:initial-state (fn [_] {:ui/step 1
:booking (fs/add-form-config BookingForm
{:id 1
:cleaning_fee "123"
:total "321"})})}
(dom/div :.container-fluid
(dom/div :.row
(dom/div :.col-md-8
(ui-booking-form (prim/computed booking {:step step}))
(dom/button {:onClick #(prim/transact! this `[(next-step {:step ~step})])} "Click")))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment