-
-
Save njj/75c31dcf4b31f1c2741026af970c42fd to your computer and use it in GitHub Desktop.
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
(defmutation update-existing-booking | |
[{:keys [booking-id]}] | |
(action | |
[{:keys [state]}] | |
(swap! state | |
(fn [s] | |
(let [booking (get-in @state [:booking/by-id booking-id]) | |
{:keys [request-update-quote]} @state] | |
(-> s | |
(update-in [:booking/by-id booking-id] merge request-update-quote))))))) | |
(defmethod m/mutation 'update-booking/request-update-quote [{:keys [state reconciler] :as env} _ {:keys [form]}] | |
{:remote (m/remote-load env) | |
:action (fn [] | |
(let [{:keys [_id cleaning_fee]} form | |
booking-params {:addtl_charge_lis [{:index 0 | |
:update {:charge_amount (js/parseFloat cleaning_fee) | |
:charge_str "Cleaning" | |
:apply_to "both_subtotals" | |
:apply_as "FLAT_RATE" | |
:value (js/parseFloat cleaning_fee) | |
:type "CLEANING_FEE"}}]}] | |
(df/load-action env :request-update-quote nil {:refresh [f/form-root-key] | |
:params {:booking-id _id | |
:booking-params booking-params} | |
:post-mutation `update-existing-booking | |
:post-mutation-params {:booking-id _id}})))}) | |
(defn editable-input | |
([component field & addon] | |
(let [form (prim/props component) | |
entity-ident (prim/get-ident component form) | |
id (str (first entity-ident) "-" (second entity-ident)) | |
value (get form field "") | |
validity (details-validator form field) | |
is-invalid? (= :invalid validity) | |
classes (if is-invalid? " form-group has-error" "form-group")] | |
(dom/div | |
{:className classes} | |
(dom/div | |
:.input-group.col-md-12 | |
(if-not (nil? addon) | |
(dom/div | |
:.input-group-addon addon)) | |
(dom/input | |
:.form-control | |
{:value (str value) | |
:id id | |
:onChange (fn [e] | |
(m/set-string! component field :event e) | |
(prim/transact! component `[(fs/mark-complete! {:field ~field | |
:entity-ident ~entity-ident}) | |
(update-booking/add-form-config {:form ~form}) | |
(update-booking/request-update-quote {:form ~form}) | |
:root/booking]))})))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment