Files
integreat/src/cljs/auto_ap/views/pages/admin/companies.cljs
2018-04-03 19:27:34 -07:00

61 lines
2.4 KiB
Clojure

(ns auto-ap.views.pages.admin.companies
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [re-frame.core :as re-frame]
[reagent.core :as reagent]
[auto-ap.subs :as subs]
[auto-ap.events :as events]
[auto-ap.views.utils :refer [login-url]]
[cljs.reader :as edn]
[auto-ap.routes :as routes]
[bidi.bidi :as bidi]))
(defn companies-table []
(let [companies (re-frame/subscribe [::subs/companies])
admin-companies (re-frame/subscribe [::subs/admin-companies])
selected-company (:selected @admin-companies)]
[:table {:class "table", :style {:width "100%"}}
[:thead
[:tr
[:th ""]
[:th "Name"]
[:th ""]]]
[:tbody (for [{:keys [id name data] :as c} @companies]
^{:key (str name "-" id )}
[:tr {:on-click (fn [] (re-frame/dispatch [::events/select-company id]))
:style {"cursor" "pointer"}}
[:td id]
[:td name]
[:td [:i.fa.fa-pencil]]])]]))
(defn admin-companies-page []
[:div {:class "inbox-messages"}
[:div.hero
[:div.hero-body
[:div.container
(let [companies (re-frame/subscribe [::subs/companies])
admin-companies (re-frame/subscribe [::subs/admin-companies])
selected-company (:selected @admin-companies)]
(if selected-company
[:div
[:h1.title "Companies > " (:name selected-company)]
[:label {:for "company-name"} "Name"]
[:input#company-name.input {:type "text" :value (:name selected-company)}]
[:label {:for "email"} "Email"]
[:input#email.input {:type "email" :value (:email selected-company)}]
[:label {:for "data"} "Data"]
[:input#data.input {:type "text" :value (:data selected-company)}]
[:label {:for "check"} "Send invoice reminders?"]
[:input#check.checkbox {:type "checkbox" :value (:send-reminders selected-company)}]
[:div]
[:a.button {:on-click (fn [] (re-frame/dispatch [::events/select-company nil]))} "Back"]
[:a.button.is-primary {:on-click (fn [] (re-frame/dispatch [::events/select-company nil]))} "Save"]]
[:div
[:h1.title "Companies"]
[companies-table]
[:a.button.is-primary "New Company"]]))]]]])