makes it look like you can add a new invoice.
This commit is contained in:
@@ -66,12 +66,17 @@
|
||||
(re-frame/reg-event-db
|
||||
::swap-company
|
||||
(fn [db [_ company]]
|
||||
(println company)
|
||||
(assoc db :company (:id company))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::change-form
|
||||
(fn [db [_ location field value]]
|
||||
(assoc-in db (into location field) value)))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::modal-status
|
||||
(fn [db [_ id state]]
|
||||
(println "changing modal status" id "to")
|
||||
(update-in db [:modal-state id] #(merge % state))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
(ns auto-ap.views.components.modal
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[reagent.core :as r]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.utils :refer [with-keys]]))
|
||||
@@ -13,8 +14,8 @@
|
||||
[:p.modal-card-title
|
||||
title]
|
||||
[:button.delete {:on-click (fn [] (re-frame/dispatch hide-event))}]]
|
||||
[:section.modal-card-body
|
||||
(with-keys body)]
|
||||
(into [:section.modal-card-body]
|
||||
(r/children (r/current-component)))
|
||||
|
||||
(when foot
|
||||
[:footer.modal-card-foot
|
||||
@@ -23,16 +24,14 @@
|
||||
(defn action-modal [{:keys [title action-text id save-event]} & 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 []
|
||||
(re-frame/dispatch [::events/modal-status id {:saving? true}])
|
||||
(re-frame/dispatch save-event))
|
||||
:class (when saving?
|
||||
"is-loading")}
|
||||
[:span action-text]]
|
||||
:id id
|
||||
:hide-event [::events/modal-status id {:visible? false}]}
|
||||
|
||||
(with-keys rest)
|
||||
|
||||
(when saving? [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])])))
|
||||
(-> [modal {:title title
|
||||
:foot [:a.button.is-primary {:on-click (fn []
|
||||
(re-frame/dispatch [::events/modal-status id {:saving? true}])
|
||||
(re-frame/dispatch save-event))
|
||||
:class (when saving?
|
||||
"is-loading")}
|
||||
[:span action-text]]
|
||||
:id id
|
||||
:hide-event [::events/modal-status id {:visible? false}]}]
|
||||
(into (r/children (r/current-component)) )
|
||||
(into [(when saving? [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])])))))
|
||||
|
||||
@@ -125,8 +125,7 @@
|
||||
[action-modal {:title (str "Edit " (:name (:user editing)))
|
||||
:id ::edit-user
|
||||
:action-text "Save"
|
||||
:save-event [::save]
|
||||
:editing editing}
|
||||
:save-event [::save]}
|
||||
[horizontal-field
|
||||
[:label.label "Name"]
|
||||
[bind-field
|
||||
@@ -139,15 +138,16 @@
|
||||
[horizontal-field
|
||||
[:label.label "Role"]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:select.select {:type "select"
|
||||
:field [:user :role]
|
||||
:spec ::entity/name
|
||||
:event ::change
|
||||
:subscription editing}
|
||||
[:option {:value "none"} "None"]
|
||||
[:option {:value "user"} "User"]
|
||||
[:option {:value "admin"} "Admin"]]]]]
|
||||
[:div.select
|
||||
[bind-field
|
||||
[:select {:type "select"
|
||||
:field [:user :role]
|
||||
:spec ::entity/name
|
||||
:event ::change
|
||||
:subscription editing}
|
||||
[:option {:value "none"} "None"]
|
||||
[:option {:value "user"} "User"]
|
||||
[:option {:value "admin"} "Admin"]]]]]]
|
||||
|
||||
|
||||
(when (= "user" (:role (:user editing)))
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[auto-ap.entities.companies :as company]
|
||||
[auto-ap.entities.vendors :as vendor]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.views.utils :refer [dispatch-event bind-field]]
|
||||
[auto-ap.views.utils :refer [dispatch-event bind-field horizontal-field]]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[auto-ap.views.pages.check :as check]
|
||||
[auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table]
|
||||
[auto-ap.views.components.modal :refer [modal]]
|
||||
[auto-ap.views.components.modal :refer [modal action-modal]]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.events :as events]))
|
||||
|
||||
@@ -26,6 +25,11 @@
|
||||
(fn [db]
|
||||
(-> db ::check-results)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::new-invoice
|
||||
(fn [db]
|
||||
(-> db ::new-invoice)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::params
|
||||
(fn [db]
|
||||
@@ -176,7 +180,17 @@
|
||||
(fn [cofx [_ params]]
|
||||
{:dispatch [::params-change @(re-frame/subscribe [::params])]}))
|
||||
|
||||
(defn modal-dialog []
|
||||
(re-frame/reg-event-fx
|
||||
::new-invoice
|
||||
(fn [{:keys [db]} _]
|
||||
{:dispatch [::events/modal-status ::new-invoice {:visible? true}]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::create-invoice
|
||||
(fn [{:keys [db]} _]
|
||||
{}))
|
||||
|
||||
(defn print-checks-modal []
|
||||
(let [{:keys [checked]} @(re-frame/subscribe [::invoice-page])
|
||||
{:keys [shown? invoices printing?] :as advanced-print-checks} @(re-frame/subscribe [::advanced-print-checks])
|
||||
current-company @(re-frame/subscribe [::subs/company])]
|
||||
@@ -224,6 +238,56 @@
|
||||
:max outstanding-balance
|
||||
:step "0.01"}]]]]]])]]])))
|
||||
|
||||
(defn new-invoice-modal []
|
||||
(let [data @(re-frame/subscribe [::new-invoice])
|
||||
change-event [::events/change-form [::new-invoice]]]
|
||||
[action-modal {:id ::new-invoice
|
||||
:title "New Invoice"
|
||||
:action-text "Create"
|
||||
:save-event [::create-invoice]}
|
||||
[horizontal-field
|
||||
[:label.label "Vendor"]
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field [:vendor]
|
||||
:event change-event
|
||||
:subscription data}]]]
|
||||
[horizontal-field
|
||||
[:label.label "Date"]
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field [:date]
|
||||
:event change-event
|
||||
:subscription data}]]]
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Company"]
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field [:company]
|
||||
:event change-event
|
||||
:subscription data}]]]
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Invoice #"]
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field [:invoice-number]
|
||||
:event change-event
|
||||
:subscription data}]]]
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Total"]
|
||||
[:div.field.has-addons.is-extended
|
||||
[:p.control [:a.button.is-static "$"]]
|
||||
[:p.control
|
||||
[bind-field
|
||||
[:input.input {:type "number"
|
||||
:field [:total]
|
||||
:event change-event
|
||||
:subscription data
|
||||
:step "0.01"}]]]]]]))
|
||||
|
||||
(def unpaid-invoices-page
|
||||
(with-meta
|
||||
(fn []
|
||||
@@ -233,6 +297,7 @@
|
||||
[:div
|
||||
[:h1.title "Unpaid invoices"]
|
||||
[:div.is-pulled-right
|
||||
[:button.button.is-danger {:on-click (dispatch-event [::new-invoice])} "New Invoice"]
|
||||
(when current-company
|
||||
[:div.dropdown.is-right {:class (if print-checks-shown?
|
||||
"is-active"
|
||||
@@ -267,7 +332,8 @@
|
||||
:on-check-changed (fn [which]
|
||||
(re-frame/dispatch [::toggle-check which]))}]
|
||||
|
||||
[modal-dialog]
|
||||
[print-checks-modal]
|
||||
[new-invoice-modal]
|
||||
(when check-results-shown?
|
||||
[modal
|
||||
{:title "Your checks are ready!"
|
||||
|
||||
Reference in New Issue
Block a user