a lot of prep for editing customers

This commit is contained in:
Bryce Covert
2018-04-05 09:09:56 -07:00
parent 1ed2b109c9
commit 23e1a7e20f
8 changed files with 110 additions and 40 deletions

View File

@@ -11,20 +11,18 @@
(defn companies-table []
(let [companies (re-frame/subscribe [::subs/companies])
admin-companies (re-frame/subscribe [::subs/admin-companies])
selected-company (:selected @admin-companies)]
editing-company (:editing @admin-companies)]
[:table {:class "table", :style {:width "100%"}}
[:thead
[:tr
[:th ""]
[:th "Name"]
[:th ""]]]
[:tbody (for [{:keys [id name data] :as c} @companies]
[:th "Email"]]]
[:tbody (for [{:keys [id name email data] :as c} @companies]
^{:key (str name "-" id )}
[:tr {:on-click (fn [] (re-frame/dispatch [::events/select-company id]))
[:tr {:on-click (fn [] (re-frame/dispatch [::events/edit-company id]))
:style {"cursor" "pointer"}}
[:td id]
[:td name]
[:td [:i.fa.fa-pencil]]])]]))
[:td email]])]]))
(defn admin-companies-page []
[:div {:class "inbox-messages"}
@@ -33,28 +31,48 @@
[:div.container
(let [companies (re-frame/subscribe [::subs/companies])
admin-companies (re-frame/subscribe [::subs/admin-companies])
selected-company (:selected @admin-companies)]
(if selected-company
[:div
[:h1.title "Companies > " (:name selected-company)]
[:label {:for "company-name"} "Name"]
[:input#company-name.input {:type "text" :value (:name selected-company)}]
editing-company (:editing @admin-companies)]
[:div
[:h1.title "Companies"]
[companies-table]
[:a.button.is-primary "New Company"]
[:label {:for "email"} "Email"]
[:input#email.input {:type "email" :value (:email selected-company)}]
[:label {:for "data"} "Data"]
[:input#data.input {:type "text" :value (:data selected-company)}]
(when editing-company
[:div.modal.is-active
[:div.modal-background {:on-click (fn [] (re-frame/dispatch [::events/edit-company nil]))}]
[:div.modal-card
[:header.modal-card-head
[:p.modal-card-title
(str "Edit " (:name editing-company))]
[:button.delete {:on-click (fn [] (re-frame/dispatch [::events/edit-company nil]))}]]
[:section.modal-card-body
[:label {:for "company-name"} "Name"]
[:input#company-name.input {:type "text" :value (:name editing-company)
:on-change (fn [e]
(re-frame/dispatch [::events/change-editing-company [:name]
(.. e -target -value)]))}]
[:label {:for "check"} "Send invoice reminders?"]
[:input#check.checkbox {:type "checkbox" :value (:send-reminders selected-company)}]
[:div]
[:a.button {:on-click (fn [] (re-frame/dispatch [::events/select-company nil]))} "Back"]
[:a.button.is-primary {:on-click (fn [] (re-frame/dispatch [::events/select-company nil]))} "Save"]]
[:div
[:h1.title "Companies"]
[companies-table]
[:a.button.is-primary "New Company"]]))]]]])
[:label {:for "email"} "Email"]
[:input#email.input {:type "email"
:value (:email editing-company)
:on-change (fn [e]
(re-frame/dispatch [::events/change-editing-company [:email]
(.. e -target -value)]))}]
[:div.control
[:label {:for "check"} "Send invoice reminders?"
[:input#check.checkbox {:type "checkbox" :value (:send-reminders editing-company)}]]]
(when (:saving? editing-company) [:div.is-overlay {:style {"background-color" "rgba(150,150,150, 0.5)"}}])]
[:footer.modal-card-foot
[:a.button.is-primary {:on-click (fn [] (re-frame/dispatch [::events/save-editing-company]))}
[:span "Save"]
(when (:saving? editing-company)
[:span.icon
[:i.fa.fa-spin.fa-spinner]])]]]])])]]]])