mirror of
https://github.com/mruwnik/chicken-master.git
synced 2025-06-08 13:24:42 +02:00
logout button
This commit is contained in:
parent
ccf3214aba
commit
37f0498ddf
@ -247,7 +247,7 @@ html body .calendar .day .product .product-name {
|
||||
html body .calendar .day .product .product-amount {
|
||||
width: 40px;
|
||||
max-height: 5px;
|
||||
margin-right: 10px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
html body .calendar .day .product .product-price {
|
||||
|
@ -70,13 +70,14 @@
|
||||
[:label {:for id} label])
|
||||
[:input (merge {:name id :id id} handlers (dissoc opts :parser))]
|
||||
(when (and label (#{:checkbox :radio} (:type opts)))
|
||||
[:label {:for id} label])
|
||||
]))
|
||||
[:label {:for id} label])]))
|
||||
|
||||
(defn settings-options []
|
||||
[:div
|
||||
[:h3 "Ustawienia używtkownika"]
|
||||
[:button {:type :button :on-click #(re-frame/dispatch [:chicken-master.events/log-out])} "wyloguj"]
|
||||
|
||||
[:h3 "Ustawienia wyglądu kalendarza"]
|
||||
[:button {:type :button :on-click #(set-item! :bearer-token nil)} "wyloguj"]
|
||||
|
||||
(input :first-day-offset "o ile dni przesunąć niedziele w lewo"
|
||||
{:type :number :max 7 :min 0 :parser #(js/parseInt %)})
|
||||
|
@ -34,15 +34,19 @@
|
||||
::initialize-db
|
||||
(fn [_ _]
|
||||
(time/update-settings config/default-settings)
|
||||
(let [user (some-> js/window (.-localStorage) (.getItem :bearer-token))]
|
||||
{:db (assoc db/default-db
|
||||
(let [user (some-> js/window (.-localStorage) (.getItem :bearer-token))
|
||||
user (when-not (= user "null") user)
|
||||
result {:db (assoc db/default-db
|
||||
:settings config/default-settings
|
||||
:current-user user)
|
||||
:dispatch [(when user ::load-db)]})))
|
||||
:current-user user)}]
|
||||
(if user
|
||||
(assoc result :dispatch [::load-db])
|
||||
result))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::load-db
|
||||
(fn [_ _]
|
||||
(prn "loading")
|
||||
(time/update-settings config/default-settings)
|
||||
{:fx [[:dispatch [::show-from-date (time/iso-date (time/today))]]
|
||||
[:dispatch [::start-loading]]
|
||||
@ -68,8 +72,8 @@
|
||||
(re-frame/reg-event-fx
|
||||
::failed-request
|
||||
(fn [{db :db} [_ response]]
|
||||
{:db (update db :current-user #(when-not (= (:status response) 401) %))
|
||||
:fx [[:dispatch [::log-error (str response)]]
|
||||
{:fx [(when (= (:status response) 401) [:dispatch [::log-out]])
|
||||
[:dispatch [::log-error (str response)]]
|
||||
[:dispatch [::stop-loading]]]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
@ -234,6 +238,11 @@
|
||||
{:db (assoc db :current-user (b64/encodeString (str (user "name") ":" (user "password"))))
|
||||
:dispatch [::load-db]}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::log-out
|
||||
(fn [db _]
|
||||
(config/set-item! :bearer-token nil)
|
||||
(dissoc db :current-user)))
|
||||
|
||||
(comment
|
||||
(re-frame/dispatch-sync [::show-stock])
|
||||
|
Loading…
x
Reference in New Issue
Block a user