From a0007c2bbce61668335e135e34f76d67fb6389f2 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Wed, 23 May 2018 12:16:18 -0700 Subject: [PATCH] adding new invoices has validation. --- src/clj/auto_ap/graphql/users.clj | 2 +- src/cljc/auto_ap/entities/invoice.cljc | 2 +- src/cljs/auto_ap/views/components/modal.cljs | 12 ++++++++++-- src/cljs/auto_ap/views/pages/unpaid_invoices.cljs | 5 +++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/clj/auto_ap/graphql/users.clj b/src/clj/auto_ap/graphql/users.clj index f4502628..2030af47 100644 --- a/src/clj/auto_ap/graphql/users.clj +++ b/src/clj/auto_ap/graphql/users.clj @@ -5,5 +5,5 @@ (defn edit-user [context args value] (users/update! (:edit_user args)) (->graphql - (users/get-by-id (:edit_user args)))) + (users/get-by-id (:id (:edit_user args))))) diff --git a/src/cljc/auto_ap/entities/invoice.cljc b/src/cljc/auto_ap/entities/invoice.cljc index 58182b40..784d5459 100644 --- a/src/cljc/auto_ap/entities/invoice.cljc +++ b/src/cljc/auto_ap/entities/invoice.cljc @@ -8,7 +8,7 @@ (s/def ::date ::shared/date) (s/def ::total ::shared/money) -(s/def ::invoice (s/keys :opt-un [::vendor-id +(s/def ::invoice (s/keys :req-un [::vendor-id ::company-id ::invoice-number ::date diff --git a/src/cljs/auto_ap/views/components/modal.cljs b/src/cljs/auto_ap/views/components/modal.cljs index eacbecb7..73d5bdce 100644 --- a/src/cljs/auto_ap/views/components/modal.cljs +++ b/src/cljs/auto_ap/views/components/modal.cljs @@ -21,13 +21,21 @@ [:footer.modal-card-foot foot])]]) -(defn action-modal [{:keys [title action-text id save-event]} & rest] +(defn action-modal [{:keys [title action-text id save-event can-submit?] :or {can-submit? true}} & rest] (let [{:keys [visible? saving?]} @(re-frame/subscribe [::subs/modal-state id])] (when visible? (-> [modal {:title title - :foot [:a.button.is-primary {:on-click (fn [] + :foot [:button.button.is-primary {:on-click (fn [] (re-frame/dispatch [::events/modal-status id {:saving? true}]) (re-frame/dispatch save-event)) + :disabled (cond saving? + "disabled" + + (not can-submit?) + "disabled" + + :else + "") :class (when saving? "is-loading")} [:span action-text]] diff --git a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs index cc483797..f3eae633 100644 --- a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs +++ b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs @@ -2,6 +2,7 @@ (:require [re-frame.core :as re-frame] [reagent.core :as r] [clojure.string :as str] + [clojure.spec.alpha :as s] [auto-ap.entities.companies :as company] [auto-ap.entities.invoice :as invoice] [auto-ap.entities.vendors :as vendor] @@ -269,11 +270,11 @@ (defn new-invoice-modal [] (let [data @(re-frame/subscribe [::new-invoice]) change-event [::events/change-form [::new-invoice]]] - (println data) [action-modal {:id ::new-invoice :title "New Invoice" :action-text "Create" - :save-event [::create-invoice]} + :save-event [::create-invoice] + :can-submit? (s/valid? ::invoice/invoice data)} [horizontal-field [:label.label "Vendor"] [bind-field