merged.
This commit is contained in:
@@ -607,6 +607,11 @@
|
|||||||
:args {:invoices {:type '(list :id)}}
|
:args {:invoices {:type '(list :id)}}
|
||||||
:resolve :mutation/approve-invoices}
|
:resolve :mutation/approve-invoices}
|
||||||
|
|
||||||
|
:merge_vendors {:type :id
|
||||||
|
:args {:from {:type :id}
|
||||||
|
:to {:type :id}}
|
||||||
|
:resolve :mutation/merge-vendors}
|
||||||
|
|
||||||
:add_and_print_invoice {:type :check_result
|
:add_and_print_invoice {:type :check_result
|
||||||
:args {:invoice {:type :add_invoice}
|
:args {:invoice {:type :add_invoice}
|
||||||
:bank_account_id {:type :id}
|
:bank_account_id {:type :id}
|
||||||
@@ -842,6 +847,7 @@
|
|||||||
:mutation/edit-client gq-clients/edit-client
|
:mutation/edit-client gq-clients/edit-client
|
||||||
:mutation/upsert-vendor gq-vendors/upsert-vendor
|
:mutation/upsert-vendor gq-vendors/upsert-vendor
|
||||||
:mutation/upsert-account gq-accounts/upsert-account
|
:mutation/upsert-account gq-accounts/upsert-account
|
||||||
|
:mutation/merge-vendors gq-vendors/merge-vendors
|
||||||
:mutation/void-invoice gq-invoices/void-invoice
|
:mutation/void-invoice gq-invoices/void-invoice
|
||||||
:mutation/unvoid-invoice gq-invoices/unvoid-invoice
|
:mutation/unvoid-invoice gq-invoices/unvoid-invoice
|
||||||
:mutation/void-payment gq-checks/void-check
|
:mutation/void-payment gq-checks/void-check
|
||||||
|
|||||||
@@ -52,4 +52,18 @@
|
|||||||
id))
|
id))
|
||||||
(->graphql))))
|
(->graphql))))
|
||||||
|
|
||||||
|
(defn merge-vendors [context {:keys [from to]} value]
|
||||||
|
(let [conn (d/connect uri)
|
||||||
|
transaction (->> (d/query {:query {:find '[?x ?a2]
|
||||||
|
:in '[$ ?vendor-from ]
|
||||||
|
:where ['[?x ?a ?vendor-from]
|
||||||
|
'[?a :db/ident ?a2]]}
|
||||||
|
:args [(d/db conn)
|
||||||
|
from]})
|
||||||
|
(mapcat (fn [[src attr]]
|
||||||
|
|
||||||
|
[[:db/retract src attr from]
|
||||||
|
[:db/add src attr to]])))
|
||||||
|
transaction (conj transaction [:db/retractEntity from])]
|
||||||
|
@(d/transact conn transaction)
|
||||||
|
to))
|
||||||
|
|||||||
@@ -107,7 +107,6 @@
|
|||||||
::modal-status
|
::modal-status
|
||||||
(fn [db [_ id state]]
|
(fn [db [_ id state]]
|
||||||
(println "changing modal status" id "to")
|
(println "changing modal status" id "to")
|
||||||
(println (:auto-ap.forms/forms db))
|
|
||||||
(-> db
|
(-> db
|
||||||
(update-in [:modal-state id] #(merge % state))
|
(update-in [:modal-state id] #(merge % state))
|
||||||
#_(dissoc :auto-ap.forms/forms)
|
#_(dissoc :auto-ap.forms/forms)
|
||||||
@@ -123,7 +122,6 @@
|
|||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::modal-completed
|
::modal-completed
|
||||||
(fn [db [_ id state]]
|
(fn [db [_ id state]]
|
||||||
(println (:auto-ap.forms/forms db))
|
|
||||||
(-> db
|
(-> db
|
||||||
(update-in [:modal-state] #(dissoc % id))
|
(update-in [:modal-state] #(dissoc % id))
|
||||||
(update :auto-ap.forms/forms dissoc id))))
|
(update :auto-ap.forms/forms dissoc id))))
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
[auto-ap.db :as db]
|
[auto-ap.db :as db]
|
||||||
[auto-ap.routes :as routes]
|
[auto-ap.routes :as routes]
|
||||||
[auto-ap.effects :as effects]
|
[auto-ap.effects :as effects]
|
||||||
|
[auto-ap.forms :as forms]
|
||||||
|
[auto-ap.subs :as subs]
|
||||||
[auto-ap.entities.vendors :as entity]
|
[auto-ap.entities.vendors :as entity]
|
||||||
[auto-ap.events :as events]
|
[auto-ap.events :as events]
|
||||||
[auto-ap.utils :refer [by]]
|
[auto-ap.utils :refer [by]]
|
||||||
@@ -27,6 +29,29 @@
|
|||||||
{})
|
{})
|
||||||
:dispatch [::events/modal-status :auto-ap.views.pages.admin.vendors/admin-vendor {:visible? true}]}))
|
:dispatch [::events/modal-status :auto-ap.views.pages.admin.vendors/admin-vendor {:visible? true}]}))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#_(re-frame/reg-event-fx
|
||||||
|
::merge-submit-clicked
|
||||||
|
[(forms/in-form :auto-ap.views.pages.admin.vendors/merge-vendors)]
|
||||||
|
(fn [{{{:keys [from-id to-id]} :data :as merge-vendors-form} :db :as g} _]
|
||||||
|
(println g)
|
||||||
|
(let [user @(re-frame/subscribe [::subs/token])]
|
||||||
|
(if (and from-id to-id)
|
||||||
|
{:db (-> merge-vendors-form
|
||||||
|
(assoc :status :loading)
|
||||||
|
(assoc :error nil))
|
||||||
|
:graphql
|
||||||
|
{:token user
|
||||||
|
:query-obj {:venia/operation {:operation/type :mutation
|
||||||
|
:operation/name "MergeVendors"}
|
||||||
|
:venia/queries [{:query/data [:merge-vendors
|
||||||
|
{:from from-id :to to-id}
|
||||||
|
[:id]]}]}
|
||||||
|
:on-success [::merge-vendors-complete]
|
||||||
|
:on-error [::forms/save-error :auto-ap.views.pages.admin.vendors/merge-vendors]}}
|
||||||
|
{:db merge-vendors-form}))))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::save
|
::save
|
||||||
(fn [{:keys [db]} _]
|
(fn [{:keys [db]} _]
|
||||||
|
|||||||
@@ -102,8 +102,12 @@
|
|||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::modal-state
|
::modal-state
|
||||||
(fn [db [_ id]]
|
(fn [db [_ id status-from]]
|
||||||
(get (:modal-state db) id)))
|
(if status-from
|
||||||
|
(assoc (get (:modal-state db) id)
|
||||||
|
:error-message (get-in db [:auto-ap.forms/forms status-from :error])
|
||||||
|
:saving? (= (get-in db [:auto-ap.forms/forms status-from :status]) :loading))
|
||||||
|
(get (:modal-state db) id))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::token
|
::token
|
||||||
|
|||||||
@@ -21,35 +21,26 @@
|
|||||||
[:footer.modal-card-foot
|
[:footer.modal-card-foot
|
||||||
foot])]])
|
foot])]])
|
||||||
|
|
||||||
(defn action-modal [{:keys [title action-text id save-event can-submit?] :or {can-submit? true}} & rest]
|
(defn action-modal [{:keys [title action-text id save-event can-submit? status-from] :or {can-submit? true}} & rest]
|
||||||
(let [{:keys [visible? saving? error-message]} @(re-frame/subscribe [::subs/modal-state id])]
|
(let [{:keys [visible? saving? error-message]} @(re-frame/subscribe [::subs/modal-state id status-from])]
|
||||||
(when visible?
|
(when visible?
|
||||||
(-> [modal {:title [:span title
|
[:form {:id id
|
||||||
|
:on-submit (fn [e]
|
||||||
|
(.preventDefault e)
|
||||||
|
(re-frame/dispatch [::events/modal-status id {:saving? true :error-message nil}])
|
||||||
|
(re-frame/dispatch save-event))}
|
||||||
|
(-> [modal {:title [:span title]
|
||||||
|
:foot [:input.button.is-primary (cond-> {:type "submit"
|
||||||
|
:form id
|
||||||
|
:class (when saving?
|
||||||
|
"is-loading")
|
||||||
|
:value action-text}
|
||||||
|
saving? (assoc :disabled "disabled")
|
||||||
|
(not can-submit?) (assoc :disabled "disabled"))
|
||||||
]
|
]
|
||||||
:foot [:input.button.is-primary {:type "submit"
|
:id id
|
||||||
:tabindex "1"
|
:hide-event [::events/modal-status id {:visible? false}]}
|
||||||
:form id
|
(when error-message
|
||||||
:disabled (cond saving?
|
[:div.notification.is-warning error-message])]
|
||||||
"disabled"
|
(into (r/children (r/current-component)))
|
||||||
|
(into [(when saving? [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]))])))
|
||||||
(not can-submit?)
|
|
||||||
"disabled"
|
|
||||||
|
|
||||||
:else
|
|
||||||
"")
|
|
||||||
:class (when saving?
|
|
||||||
"is-loading")
|
|
||||||
:value action-text}
|
|
||||||
]
|
|
||||||
:id id
|
|
||||||
:hide-event [::events/modal-status id {:visible? false}]}
|
|
||||||
(into [:form {:id id
|
|
||||||
:on-submit (fn [e]
|
|
||||||
(.preventDefault e)
|
|
||||||
(re-frame/dispatch [::events/modal-status id {:saving? true :error-message nil}])
|
|
||||||
(re-frame/dispatch save-event))}
|
|
||||||
(when error-message
|
|
||||||
[:div.notification.is-warning error-message])]
|
|
||||||
|
|
||||||
(r/children (r/current-component)) )]
|
|
||||||
(into [(when saving? [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])])))))
|
|
||||||
|
|||||||
@@ -5,10 +5,12 @@
|
|||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[auto-ap.subs :as subs]
|
[auto-ap.subs :as subs]
|
||||||
[auto-ap.events :as main-events]
|
[auto-ap.events :as main-events]
|
||||||
|
[auto-ap.forms :as forms]
|
||||||
[auto-ap.events.admin.vendors :as events]
|
[auto-ap.events.admin.vendors :as events]
|
||||||
[auto-ap.entities.vendors :as entity]
|
[auto-ap.entities.vendors :as entity]
|
||||||
[auto-ap.views.components.address :refer [address-field]]
|
[auto-ap.views.components.address :refer [address-field]]
|
||||||
[auto-ap.views.components.modal :refer [modal]]
|
[auto-ap.views.components.vendor-dialog :refer [vendor-dialog]]
|
||||||
|
[auto-ap.views.components.modal :refer [modal action-modal]]
|
||||||
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
|
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
|
||||||
[auto-ap.views.components.layouts :refer [side-bar-layout]]
|
[auto-ap.views.components.layouts :refer [side-bar-layout]]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
@@ -55,6 +57,72 @@
|
|||||||
keys (dissoc keys :field :subscription)]
|
keys (dissoc keys :field :subscription)]
|
||||||
(vec (concat [dom keys] rest))))
|
(vec (concat [dom keys] rest))))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::merge-clicked
|
||||||
|
(fn [{:keys [db]} _]
|
||||||
|
{:db (forms/start-form db ::merge-vendors {})
|
||||||
|
:dispatch [::main-events/modal-status ::merge-vendors {:visible? true :saving? false}]}))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::merge-vendors-complete
|
||||||
|
(fn [{:keys [db]} _]
|
||||||
|
{:db (forms/stop-form db ::merge-vendors)
|
||||||
|
:dispatch-n (list [::main-events/modal-status ::merge-vendors {:visible? false}]
|
||||||
|
[::events/mounted])}))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::merge-submit-clicked
|
||||||
|
[(forms/in-form ::merge-vendors)]
|
||||||
|
(fn [{{{:keys [from-id to-id]} :data :as merge-vendors-form} :db :as g} _]
|
||||||
|
(let [user @(re-frame/subscribe [::subs/token])]
|
||||||
|
(if (and from-id to-id)
|
||||||
|
{:db (-> merge-vendors-form
|
||||||
|
(assoc :status :loading)
|
||||||
|
(assoc :error nil))
|
||||||
|
:graphql
|
||||||
|
{:token user
|
||||||
|
:query-obj {:venia/operation {:operation/type :mutation
|
||||||
|
:operation/name "MergeVendors"}
|
||||||
|
:venia/queries [{:query/data [:merge-vendors
|
||||||
|
{:from from-id :to to-id}
|
||||||
|
[]]}]}
|
||||||
|
:on-success [::merge-vendors-complete]
|
||||||
|
:on-error [::forms/save-error ::merge-vendors]}}
|
||||||
|
{:db merge-vendors-form}))))
|
||||||
|
|
||||||
|
(defn merge-vendors-dialog []
|
||||||
|
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::merge-vendors])
|
||||||
|
change-event [::forms/change ::merge-vendors]]
|
||||||
|
|
||||||
|
[action-modal {:id ::merge-vendors
|
||||||
|
:title "Merge Vendors"
|
||||||
|
:action-text "Merge"
|
||||||
|
:save-event [::merge-submit-clicked]
|
||||||
|
:status-from ::merge-vendors}
|
||||||
|
[:div.field
|
||||||
|
[:label.label
|
||||||
|
"From Vendor (will be deleted)"]
|
||||||
|
[:div.control
|
||||||
|
[bind-field
|
||||||
|
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/vendors]))
|
||||||
|
:type "typeahead"
|
||||||
|
:auto-focus true
|
||||||
|
:field [:from-id]
|
||||||
|
:text-field [:from-name]
|
||||||
|
:event change-event
|
||||||
|
:subscription data}]]]]
|
||||||
|
[:div.field
|
||||||
|
[:label.label
|
||||||
|
"To Vendor"]
|
||||||
|
[:div.control
|
||||||
|
[bind-field
|
||||||
|
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/vendors]))
|
||||||
|
:type "typeahead"
|
||||||
|
:field [:to-id]
|
||||||
|
:text-field [:to-name]
|
||||||
|
:event change-event
|
||||||
|
:subscription data}]]]]]))
|
||||||
|
|
||||||
|
|
||||||
(defn admin-vendors-content []
|
(defn admin-vendors-content []
|
||||||
[(with-meta
|
[(with-meta
|
||||||
@@ -64,16 +132,18 @@
|
|||||||
[:div.notification banner])
|
[:div.notification banner])
|
||||||
(let [vendors (re-frame/subscribe [::subs/vendors])
|
(let [vendors (re-frame/subscribe [::subs/vendors])
|
||||||
editing-vendor (:vendor @(re-frame/subscribe [::subs/admin]))]
|
editing-vendor (:vendor @(re-frame/subscribe [::subs/admin]))]
|
||||||
|
|
||||||
|
|
||||||
[:div
|
[:div
|
||||||
[:h1.title "Vendors"]
|
[:h1.title "Vendors"]
|
||||||
|
[:a.button.is-primary.is-large {:on-click (dispatch-event [::merge-clicked])} "Merge vendors"]
|
||||||
[vendors-table]
|
[vendors-table]
|
||||||
|
|
||||||
[:div.is-pulled-right
|
[:div.is-pulled-right
|
||||||
[:a.button.is-primary.is-large {:on-click (dispatch-event [::main-events/modal-status :auto-ap.views.main/user-editing-vendor {:visible? true}])} "New vendor"]]
|
[:a.button.is-primary.is-large {:on-click (dispatch-event [::main-events/modal-status :auto-ap.views.main/user-editing-vendor {:visible? true}])} "New vendor"]]
|
||||||
|
[merge-vendors-dialog]
|
||||||
])])
|
[vendor-dialog {:vendor editing-vendor
|
||||||
|
:save-event [::events/save]
|
||||||
|
:change-event ::events/change
|
||||||
|
:id ::admin-vendor}]])])
|
||||||
{:component-did-mount (fn []
|
{:component-did-mount (fn []
|
||||||
(re-frame/dispatch [::events/mounted]))})])
|
(re-frame/dispatch [::events/mounted]))})])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user