many more fields.

This commit is contained in:
Bryce Covert
2018-04-09 08:47:46 -07:00
parent 934e7c7bf6
commit 87b94f0f3f
4 changed files with 218 additions and 38 deletions

View File

@@ -21,17 +21,18 @@
::save
(fn [{:keys [db]} _]
(let [edited-vendor (get-in db [:admin :vendor])
fx {:db (assoc-in db [:admin :vendor :saving?] true)}]
fx {:db (assoc-in db [:admin :vendor :saving?] true)}
all-fields [:name :email :data :invoice-reminder-schedule :primary-contact :primary-email :primary-phone :secondary-contact :secondary-email :secondary-phone :code :address1 :address2 :city :state :zip]]
(if (:id edited-vendor)
(assoc fx :http {:method :put
:token (:user db)
:body (pr-str (select-keys edited-vendor [:name :email :data :invoice-reminder-schedule :code]))
:body (pr-str (select-keys edited-vendor all-fields))
:headers {"Content-Type" "application/edn"}
:uri (str "/api/vendors/" (:id edited-vendor))
:on-success [::save-complete]})
(assoc fx :http {:method :post
:token (:user db)
:body (pr-str (select-keys edited-vendor [:name :email :data :invoice-reminder-schedule :code]))
:body (pr-str (select-keys edited-vendor all-fields))
:headers {"Content-Type" "application/edn"}
:uri (str "/api/vendors")
:on-success [::save-complete]})))))

View File

@@ -17,16 +17,16 @@
[:th "Name"]
[:th "Email"]
[:th "Invoice Reminders"]]]
[:tbody (for [{:keys [id name email data invoice-reminder-schedule]} @vendors]
[:tbody (for [{:keys [id name primary-email data invoice-reminder-schedule]} @vendors]
^{:key (str name "-" id )}
[:tr {:on-click (fn [] (re-frame/dispatch [::events/edit id]))
:style {"cursor" "pointer"}}
[:td name]
[:td email]
[:td primary-email]
[:td invoice-reminder-schedule]])]]))
(defn edit-dialog []
(let [{:keys [name email invoice-reminder-schedule id code] :as editing-vendor} (:vendor @(re-frame/subscribe [::subs/admin]))]
(let [{:keys [name city state zip address1 address2 primary-contact primary-email primary-phone secondary-contact secondary-email secondary-phone invoice-reminder-schedule id code] :as editing-vendor} (:vendor @(re-frame/subscribe [::subs/admin]))]
[:div.modal.is-active
[:div.modal-background {:on-click (fn [] (re-frame/dispatch [::events/edit nil]))}]
@@ -38,39 +38,147 @@
(str "Add " (or name "<new vendor>")))]
[:button.delete {:on-click (fn [] (re-frame/dispatch [::events/edit nil]))}]]
[:section.modal-card-body
[:div.field
[:label.label "Name"]
[:div.control
[:input.input {:type "text" :value name
:on-change (dispatch-value-change [::events/change [:name]])}]]]
[:div.field
[:label.label "Code"]
[:div.control
[:input.input {:type "text" :value code
:on-change (dispatch-value-change [::events/change [:code]])}]]
[:p.help "The vendor code is used for invoice parsing. Only one vendor at a time can use a code"]]
[:div.field.is-horizontal
[:div.field-label
[:label.label "Name"]]
[:div.field-body
[:div.field
[:div.control
[:input.input {:type "text" :value name
:on-change (dispatch-value-change [::events/change [:name]])}]]]]]
[:div.field.is-horizontal
[:div.field-label
[:label.label "Code"]]
[:div.field-body
[:div.field
[:div.control
[:input.input.is-expanded {:type "text" :value code
:on-change (dispatch-value-change [::events/change [:code]])}]
[:p.help "The vendor code is used for invoice parsing. Only one vendor at a time can use a code"]]]]
]
[:div.field
[:label.label "Email"]
[:div.control
[:input.input {:type "email"
:value email
:on-change (dispatch-value-change [::events/change [:email]])}]]]
[:h2.subtitle "Address"]
[:div.field.is-horizontal
[:div.field-label]
[:div.field-body
[:div.field
[:div.control
[:p.help "Address"]
[:input.input.is-expanded {:type "text"
:placeholder "1700 Pennsylvania Ave"
:value address1
:on-change (dispatch-value-change [::events/change [:address1]])}]]]]]
[:div.field.is-horizontal
[:div.field-label]
[:div.field-body
[:div.field
[:div.control
[:input.input.is-expanded {:type "text"
:placeholder "Suite 400"
:value address2
:on-change (dispatch-value-change [::events/change [:address2]])}]]]]]
[:div.field.is-horizontal
[:div.field-label]
[:div.field-body
[:div.field
[:p.help "City"]
[:div.control
[:input.input.is-expanded {:type "text"
:value city
:placeholder "Cupertino"
:on-change (dispatch-value-change [::events/change [:city]])}]]]
[:div.field
[:div.control
[:p.help "State"]
[:input.input {:type "email"
:value state
:placeholder "CA"
:on-change (dispatch-value-change [::events/change [:state]])}]
]]
[:div.field
[:labal.label "Invoice Reminders"]
[:div.control
[:label.radio
[:input {:type "radio"
:name "schedule"
:value "Weekly"
:checked (if (= "Weekly" invoice-reminder-schedule)
"checked"
"")
:on-change (dispatch-value-change [::events/change [:invoice-reminder-schedule]])}]
" Send weekly"]]
[:div.control
[:label.radio
[:div.field
[:div.control
[:p.help "Zip"]
[:input.input {:type "phone"
:value zip
:placeholder "95014"
:on-change (dispatch-value-change [::events/change [:zip]])}]
]]]]
[:h2.subtitle "Contact"]
[:div.field.is-horizontal
[:div.field-label
[:label.label "Primary"]]
[:div.field-body
[:div.field
[:div.control.has-icons-left
[:input.input.is-expanded {:type "text"
:value primary-contact
:on-change (dispatch-value-change [::events/change [:primary-contact]])}]
[:span.icon.is-small.is-left
[:i.fa.fa-user]]]]
[:div.field
[:div.control.has-icons-left
[:span.icon.is-small.is-left
[:i.fa.fa-envelope]]
[:input.input {:type "email"
:value primary-email
:on-change (dispatch-value-change [::events/change [:primary-email]])}]]]
[:div.field
[:div.control.has-icons-left
[:input.input {:type "phone"
:value primary-phone
:on-change (dispatch-value-change [::events/change [:primary-phone]])}]
[:span.icon.is-small.is-left
[:i.fa.fa-phone]]]]]]
[:div.field.is-horizontal
[:div.field-label
[:label.label "Secondary"]]
[:div.field-body
[:div.field
[:div.control.has-icons-left
[:input.input.is-expanded {:type "text"
:value secondary-contact
:on-change (dispatch-value-change [::events/change [:secondary-contact]])}]
[:span.icon.is-small.is-left
[:i.fa.fa-user]]]]
[:div.field
[:div.control.has-icons-left
[:span.icon.is-small.is-left
[:i.fa.fa-envelope]]
[:input.input {:type "email"
:value secondary-email
:on-change (dispatch-value-change [::events/change [:secondary-email]])}]]]
[:div.field
[:div.control.has-icons-left
[:input.input {:type "phone"
:value secondary-phone
:on-change (dispatch-value-change [::events/change [:secondary-phone]])}]
[:span.icon.is-small.is-left
[:i.fa.fa-phone]]]]]]
[:div.field.is-horizontal
[:div.field-label
[:label.label "Invoice Reminders"]]
[:div.field-body
[:div.field
[:div.control
[:label.radio
[:input {:type "radio"
:name "schedule"
:value "Weekly"
:checked (if (= "Weekly" invoice-reminder-schedule)
"checked"
"")
:on-change (dispatch-value-change [::events/change [:invoice-reminder-schedule]])}]
" Send weekly"]
[:label.radio
[:input {:type "radio"
:name "schedule"
:value "Never"
@@ -78,7 +186,8 @@
"checked"
"")
:on-change (dispatch-value-change [::events/change [:invoice-reminder-schedule]])}]
" Never"]]]
" Never"]]]]
]
(when (:saving? editing-vendor) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]