mirror of
https://github.com/mruwnik/chicken-master.git
synced 2025-06-08 21:34:43 +02:00
add new stock
This commit is contained in:
parent
d5562736f1
commit
f361882a3f
@ -124,6 +124,7 @@
|
||||
]
|
||||
|
||||
[:.customers-modal
|
||||
[:details {:padding "0.5em"}]
|
||||
[:details.customer-order {:margin-left "1em" :padding "0.5em"}
|
||||
[:.order-date-picker {:display :inline-block :width "75%" :cursor :pointer}]
|
||||
[:.product-item-edit {:margin-left "1em"}]]]
|
||||
|
@ -8,27 +8,12 @@
|
||||
[chicken-master.html :as html]
|
||||
[chicken-master.events :as event]))
|
||||
|
||||
(defn item-adder [& {:keys [type value callback button class]
|
||||
:or {type :text value "" button nil}}]
|
||||
(let [state (reagent/atom value)]
|
||||
(fn []
|
||||
[:div {:class class :on-click #(.stopPropagation %)}
|
||||
[:input {:type type :name :user-name :default value :value @state
|
||||
:on-change #(let [val (-> % .-target .-value)]
|
||||
(reset! state val)
|
||||
(if-not button (callback val)))}]
|
||||
(if button
|
||||
[:button {:class :add-product
|
||||
:type :button
|
||||
:disabled (= @state "")
|
||||
:on-click (if callback #(-> state (reset-vals! value) first callback))} button])])))
|
||||
|
||||
(defn order-adder [order]
|
||||
(let [state (reagent/atom order)]
|
||||
(fn []
|
||||
[:details {:class :customer-order :key (gensym) :open (:open @state)}
|
||||
[:summary {:on-click #(swap! state update :open not)}
|
||||
[item-adder
|
||||
[prod/item-adder
|
||||
:type :date
|
||||
:value (:day @state)
|
||||
:class :order-date-picker
|
||||
@ -42,7 +27,7 @@
|
||||
:clients
|
||||
[:div {:class :customers-modal}
|
||||
[:h2 "Clienci"]
|
||||
[item-adder :callback #(re-frame/dispatch [::event/add-customer %]) :button "+"]
|
||||
[prod/item-adder :callback #(re-frame/dispatch [::event/add-customer %]) :button "+"]
|
||||
(let [client-orders (->> @(re-frame/subscribe [::subs/orders])
|
||||
vals
|
||||
(group-by #(get-in % [:who :id])))]
|
||||
|
@ -209,10 +209,9 @@
|
||||
(assoc-in db [:products product] i)))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::set-stock-amount
|
||||
(fn [db [_ product i]]
|
||||
(prn i)
|
||||
(assoc-in db [:products product] i)))
|
||||
::delete-product
|
||||
(fn [db [_ product]]
|
||||
(update db :products dissoc product)))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::save-stock
|
||||
|
@ -78,3 +78,18 @@
|
||||
(if (settings :editable-number-inputs)
|
||||
(number-input (str "amount-" product) "" amount nil)
|
||||
[:span {:class :product-amount} amount])])
|
||||
|
||||
(defn item-adder [& {:keys [type value callback button class]
|
||||
:or {type :text value "" button nil}}]
|
||||
(let [state (reagent/atom value)]
|
||||
(fn []
|
||||
[:div {:class class :on-click #(.stopPropagation %)}
|
||||
[:input {:type type :name :user-name :default value :value @state
|
||||
:on-change #(let [val (-> % .-target .-value)]
|
||||
(reset! state val)
|
||||
(if-not button (callback val)))}]
|
||||
(if button
|
||||
[:button {:class :add-product
|
||||
:type :button
|
||||
:disabled (= @state "")
|
||||
:on-click (if callback #(-> state (reset-vals! value) first callback))} button])])))
|
||||
|
@ -2,7 +2,7 @@
|
||||
(:require
|
||||
[re-frame.core :as re-frame]
|
||||
[chicken-master.config :refer [settings]]
|
||||
[chicken-master.products :refer [num-or-nil number-input]]
|
||||
[chicken-master.products :as prod]
|
||||
[chicken-master.subs :as subs]
|
||||
[chicken-master.html :as html]
|
||||
[chicken-master.events :as event]))
|
||||
@ -12,20 +12,25 @@
|
||||
(html/modal
|
||||
:stock
|
||||
[:div {:class :stock-modal}
|
||||
[:button {:class :add-product :type :button :on-click #(re-frame/dispatch [::event/add-stock-product])} "dodaj"]
|
||||
[:h2 "Magazyn"]
|
||||
(for [[product amount] @(re-frame/subscribe [::subs/available-products])]
|
||||
[:div {:key (gensym) :class :stock-product}
|
||||
[:span {:class :product-name} product]
|
||||
[:div {:class :stock-product-amount}
|
||||
[:button {:type :button :on-click #(re-frame/dispatch [::event/update-product-stock product -1])} "-"]
|
||||
(number-input (name product) "" (or amount 0)
|
||||
#(re-frame/dispatch [::event/set-stock-amount product (-> % .-target .-value num-or-nil)]))
|
||||
(prod/number-input (name product) "" (or amount 0)
|
||||
#(re-frame/dispatch [::event/set-stock-amount product (-> % .-target .-value prod/num-or-nil)]))
|
||||
[:button {:type :button :on-click #(re-frame/dispatch [::event/update-product-stock product 1])} "+"]
|
||||
]])]
|
||||
[:button {:type :button :on-click #(re-frame/dispatch [::event/delete-product product])} "x"]
|
||||
]])
|
||||
[prod/item-adder :callback #(re-frame/dispatch [::event/set-stock-amount % 0]) :button "+"]
|
||||
]
|
||||
;; On success
|
||||
(fn [form]
|
||||
(->> form
|
||||
(reduce-kv #(assoc %1 (keyword %2) (num-or-nil %3)) {})
|
||||
(reduce-kv #(if-let [val (prod/num-or-nil %3)]
|
||||
(assoc %1 (keyword %2) val)
|
||||
%1)
|
||||
{})
|
||||
(conj [::event/save-stock])
|
||||
re-frame/dispatch))))
|
||||
|
Loading…
x
Reference in New Issue
Block a user