removed redundant stuff.

This commit is contained in:
2022-07-22 22:55:26 -07:00
parent 7f5a2ea353
commit 005bfe2603
21 changed files with 357 additions and 399 deletions

View File

@@ -269,7 +269,7 @@
[:vendor {:optional true}
[:maybe schema/reference]]
[:transaction-approval-status {:optional true}
[:maybe [:enum :unapproved :requires-feedback :approved :excluded]]]
[:maybe schema/approval-status]]
[:note {:optional true}
[:maybe :string]]]))

View File

@@ -11,29 +11,6 @@
[malli.core :as m]
[re-frame.core :as re-frame]))
(re-frame/reg-event-fx
::saving
[with-user (forms/in-form ::form)]
(fn [{:keys [db user]} [_]]
{:graphql
{:token user
:owns-state {:single ::form}
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "EditUser"}
:venia/queries [{:query/data [:edit-user
{:edit-user (-> (:data db)
(update :clients #(map (comp :id :client) %))
(select-keys #{:id :name :clients :role}))}
[:id :name :role [:clients [:id :name]]]]}]}
:on-success [::saved]}}))
(re-frame/reg-event-fx
::saved
(forms/triggers-stop ::form)
(fn [_ _]
{:dispatch [::modal/modal-closed]}))
(def client-schema
(m/schema [:map [:client schema/reference]]))
@@ -46,11 +23,40 @@
[:maybe
[:sequential client-schema]]]]))
(re-frame/reg-event-fx
::saving
[with-user (forms/in-form ::form)]
(fn [{:keys [db user]} [_]]
(if (m/validate user-schema (:data db))
{:graphql
{:token user
:owns-state {:single ::form}
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "EditUser"}
:venia/queries [{:query/data [:edit-user
{:edit-user (-> (:data db)
(update :clients #(map (comp :id :client) %))
(select-keys #{:id :name :clients :role}))}
[:id :name :role [:clients [:id :name]]]]}]}
:on-success [::saved]}}
{:dispatch-n [[::forms/attempted-submit ::form]
[::status/error ::form [{:message "Please fix the errors and try again."}]]]})
))
(re-frame/reg-event-fx
::saved
(forms/triggers-stop ::form)
(fn [_ _]
{:dispatch [::modal/modal-closed]}))
(defn form []
(let [{:keys [data]} @(re-frame/subscribe [::forms/form ::form])
clients @(re-frame/subscribe [::subs/clients])]
(println data)
[:<>
[form-builder/builder {:submit-event [::saving]
:id ::form

View File

@@ -1,43 +1,40 @@
(ns auto-ap.views.pages.admin.vendors.merge-dialog
(:require
[auto-ap.forms :as forms]
[auto-ap.forms.builder :as form-builder]
[auto-ap.schema :as schema]
[auto-ap.status :as status]
[auto-ap.subs :as subs]
[auto-ap.views.components :as com]
[auto-ap.views.components.modal :as modal]
[auto-ap.views.components.typeahead.vendor
:refer [search-backed-typeahead]]
[auto-ap.views.utils :refer [dispatch-event]]
[re-frame.core :as re-frame]
[auto-ap.forms.builder :as form-builder]))
[malli.core :as m]
[re-frame.core :as re-frame]))
(re-frame/reg-sub
::can-submit
:<- [::forms/form ::form]
(fn [{:keys [data]}]
(and (:from data)
(:to data))))
(def merge-schema
(m/schema [:map
[:from schema/reference]
[:to schema/reference]]))
(defn form []
[form-builder/builder {:submit-event [::save]
:can-submit [::can-submit]
:id ::form}
[form-builder/field "Form Vendor (will be deleted)"
[search-backed-typeahead {:search-query (fn [i]
[:search_vendor
{:query i}
[:name :id]])
:type "typeahead-v3"
:auto-focus true
:field [:from]}]]
[form-builder/builder {:submit-event [::try-save]
:id ::form
:schema merge-schema}
[form-builder/field-v2 {:field :from}
"Form Vendor (will be deleted)"
[com/search-backed-typeahead {:search-query (fn [i]
[:search_vendor
{:query i}
[:name :id]])
:auto-focus true}]]
[form-builder/field "To Vendor"
[search-backed-typeahead {:search-query (fn [i]
[:search_vendor
{:query i}
[:name :id]])
:type "typeahead-v3"
:field [:to]}]]
[form-builder/field-v2 {:field :to}
"To Vendor"
[com/search-backed-typeahead {:search-query (fn [i]
[:search_vendor
{:query i}
[:name :id]])}]]
[form-builder/hidden-submit-button]])
(re-frame/reg-event-fx
@@ -48,8 +45,7 @@
:confirm {:value "Merge"
:status-from [::status/single ::form]
:class "is-primary"
:on-click (dispatch-event [::save])
:can-submit [::can-submit]
:on-click (dispatch-event [::try-save])
:close-event [::status/completed ::form]}}]
:db (forms/start-form db ::form {})}))
@@ -73,3 +69,12 @@
{:from (:id from) :to (:id to)} []]}]}
:on-success [::complete]}})))
(re-frame/reg-event-fx
::try-save
[(forms/in-form ::form)]
(fn [{:keys [db]}]
(if (not (m/validate merge-schema (:data db)))
{:dispatch-n [[::status/error ::form [{:message "Please correct any errors and try again"}]]
[::forms/attempted-submit ::form]]}
{:dispatch [::save]})))