added bad dialog idea.

This commit is contained in:
Bryce Covert
2020-04-19 08:16:35 -07:00
parent fc9f94a64d
commit 5579fc95b2
8 changed files with 329 additions and 707 deletions

View File

@@ -1,9 +1,10 @@
(ns auto-ap.views.components.vendor-dialog
(:require [re-frame.core :as re-frame]
[auto-ap.views.utils :refer [dispatch-event horizontal-field bind-field with-user]]
[auto-ap.views.utils :refer [dispatch-event horizontal-field bind-field with-user active-when]]
[auto-ap.views.components.modal :refer [action-modal]]
[auto-ap.views.components.address :refer [address-field]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.components.dropdown :refer [drop-down drop-down-contents]]
[auto-ap.events :as events]
[clj-fuzzy.metrics :refer [jaccard jaro-winkler]]
[clojure.spec.alpha :as s]
@@ -12,6 +13,7 @@
[auto-ap.entities.contact :as contact]
[auto-ap.subs :as subs]
[auto-ap.forms :as forms]))
(defn ngrams [text len]
(mapv #(.toLowerCase (str/join "" %))
(partition len 1 text)))
@@ -31,6 +33,22 @@
(map first)
first))))
(re-frame/reg-sub
::selected-override
(fn [db]
(::selected-override db)))
(re-frame/reg-event-db
::override-selected
(fn [db [_ which]]
(assoc db ::selected-override which)))
(re-frame/reg-event-db
::override-added
(fn [db [_ z]]
(println "selected" z)
(assoc db ::selected-override "101")))
(re-frame/reg-event-fx
::started
(fn [{:keys [db]} [_ vendor]]
@@ -41,7 +59,6 @@
(update :default-account
(fn [da]
@(re-frame/subscribe [::subs/account (:id da)]))))))
:dispatch [::events/modal-status ::dialog {:visible? true}]}))
(re-frame/reg-event-fx
@@ -69,35 +86,17 @@
:on-success [::save-complete]
:on-error [::forms/save-error ::vendor-form]}})))
(defn vendor-dialog [{:keys [save-event] }]
(let [clients-by-id @(re-frame/subscribe [::subs/clients-by-id])
all-vendors @(re-frame/subscribe [::subs/vendors])
chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts])
{:keys [data error ] :as f} @(re-frame/subscribe [::forms/form ::vendor-form])
change-event [::forms/change ::vendor-form]]
[action-modal {:id ::dialog
:title [:span (if (:id data)
(str "Edit " (or (:name data) "<vendor>"))
(str "Add " (or (:name data) "<new vendor>")))
(when error
[:span.icon.has-text-danger
[:i.fa.fa-exclamation-triangle]])]
:status-from ::vendor-form
:warning
(when-let [vendor (partial-matches-vendor? data all-vendors)]
(str "Are you sure you don't mean " vendor "?"))
:action-text "Save"
:save-event [::save]
:can-submit? (s/valid? ::entity/vendor data)}
(defn form-content [{:keys [data change-event selected-override]}]
(let [chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts])
root-path (cond-> [] selected-override (into [:overrides selected-override]))]
[:div
[horizontal-field
[:label.label "Name"]
[:div.control
[bind-field
[:input.input {:type "text"
:auto-focus true
:field :name
:field (conj root-path :name)
:spec ::entity/name
:event change-event
:subscription data}]]]]
@@ -107,7 +106,7 @@
[:div.control
[bind-field
[:input.input {:type "text"
:field :print-as
:field (conj root-path :print-as)
:spec ::entity/print-as
:event change-event
:subscription data}]]]]
@@ -118,7 +117,7 @@
[bind-field
[:input.input {:type "number"
:step "1"
:field :terms
:field (conj root-path :terms)
:spec ::entity/terms
:event change-event
:subscription data}]]]]
@@ -128,10 +127,10 @@
[:div.control
[bind-field
[:input {:type "checkbox"
:field :hidden
:spec ::entity/hidden
:event change-event
:subscription data}]]]]
:field (conj root-path :hidden)
:spec ::entity/hidden
:event change-event
:subscription data}]]]]
[:h2.subtitle "Expense Accounts"]
[horizontal-field
@@ -141,12 +140,12 @@
[typeahead-entity {:matches chooseable-expense-accounts
:match->text (fn [x ] (str (:numeric-code x) " - " (:name x)))
:type "typeahead-entity"
:field [:default-account]
:field (conj root-path :default-account)
:event change-event
:subscription data}]]]
[:h2.subtitle "Address"]
[address-field {:field [:address]
[address-field {:field (conj root-path :address)
:event change-event
:subscription data}]
[:h2.subtitle "Contact"]
@@ -155,7 +154,7 @@
[:div.control.has-icons-left
[bind-field
[:input.input.is-expanded {:type "text"
:field [:primary-contact :name]
:field (into root-path [:primary-contact :name])
:spec ::contact/name
:event change-event
:subscription data}]]
@@ -167,7 +166,7 @@
[:i.fa.fa-envelope]]
[bind-field
[:input.input {:type "email"
:field [:primary-contact :email]
:field (into root-path [:primary-contact :email])
:spec ::contact/email
:event change-event
:subscription data}]]]
@@ -175,7 +174,7 @@
[:div.control.has-icons-left
[bind-field
[:input.input {:type "phone"
:field [:primary-contact :phone]
:field (into root-path [:primary-contact :phone])
:spec ::contact/phone
:event change-event
:subscription data}]]
@@ -186,7 +185,7 @@
[:div.control.has-icons-left
[bind-field
[:input.input.is-expanded {:type "text"
:field [:secondary-contact :name]
:field (into root-path [:secondary-contact :name])
:spec ::contact/name
:event change-event
:subscription data}]]
@@ -197,14 +196,14 @@
[:i.fa.fa-envelope]]
[bind-field
[:input.input {:type "email"
:field [:secondary-contact :email]
:field (into root-path [:secondary-contact :email])
:spec ::contact/email
:event change-event
:subscription data}]]]
[:div.control.has-icons-left
[bind-field
[:input.input {:type "phone"
:field [:secondary-contact :phone]
:field (into root-path [:secondary-contact :phone])
:spec ::contact/phone
:event change-event
:subscription data}]]
@@ -218,7 +217,7 @@
[:input {:type "radio"
:name "schedule"
:value "Weekly"
:field :invoice-reminder-schedule
:field (conj root-path :invoice-reminder-schedule)
:spec ::entity/invoice-reminder-schedule
:event change-event
:subscription data}]]
@@ -229,9 +228,59 @@
[:input {:type "radio"
:name "schedule"
:value "Never"
:field :invoice-reminder-schedule
:field (conj root-path :invoice-reminder-schedule)
:spec ::entity/invoice-reminder-schedule
:event change-event
:subscription data}]]
" Never"]]]
(when (:saving? data) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]))
" Never"]]]]))
(defn vendor-dialog [{:keys [save-event] }]
(let [clients @(re-frame/subscribe [::subs/clients])
all-vendors @(re-frame/subscribe [::subs/vendors])
selected-override @(re-frame/subscribe [::selected-override])
{:keys [data error ] :as f} @(re-frame/subscribe [::forms/form ::vendor-form])
change-event [::forms/change ::vendor-form]]
[action-modal {:id ::dialog
:title [:span (if (:id data)
(str "Edit " (or (:name data) "<vendor>"))
(str "Add " (or (:name data) "<new vendor>")))
(when error
[:span.icon.has-text-danger
[:i.fa.fa-exclamation-triangle]])]
:status-from ::vendor-form
#_#_:warning
(when-let [vendor (partial-matches-vendor? data all-vendors)]
(str "Are you sure you don't mean " vendor "?"))
:action-text "Save"
:save-event [::save]
:can-submit? (s/valid? ::entity/vendor data)}
[:div
[:div.level
[:div.level-left
[:div.tabs
[:ul
[:li {:class (active-when selected-override = nil)}
[:a {:on-click (dispatch-event [::override-selected nil])} "All"]]
[:li {:class (active-when selected-override = "123")}
[:a {:on-click (dispatch-event [::override-selected "123"])}
[:span "Campbell Brewing Company"]]]
]]]
[:div.level-right
[drop-down {:id [::add-new-override]
:is-right? true
:header [:a.button.badge {:aria-haspopup true
:on-click (dispatch-event [::events/toggle-menu [::add-new-override]])}
[:span.icon
[:span.icon-add]]
[:span "Override"]]}
[drop-down-contents
[:div
[:div.field
[:label.label "Client"]
[typeahead-entity {:matches clients
:match->text :name
:type "typeahead-entity"
:event [:override-added]}]]]]]]]
[form-content {:data data :change-event change-event
:selected-override selected-override}]]]))