feat(grfn/bbbg): Display + allow editing attendee notes

Change-Id: I75353d64651a19beb44d3726d2645608bac0cde5
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4505
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
This commit is contained in:
Griffin Smith 2021-12-19 13:39:51 -05:00 committed by clbot
parent 562236085b
commit 736ef8ce41

View file

@ -5,14 +5,16 @@
[bbbg.db.attendee :as db.attendee] [bbbg.db.attendee :as db.attendee]
[bbbg.db.event :as db.event] [bbbg.db.event :as db.event]
[bbbg.event :as event] [bbbg.event :as event]
[bbbg.handlers.core :refer [page-response wrap-auth-required]]
[bbbg.views.flash :as flash]
[cheshire.core :as json] [cheshire.core :as json]
[compojure.coercions :refer [as-uuid]]
[compojure.core :refer [GET POST routes]] [compojure.core :refer [GET POST routes]]
[honeysql.helpers :refer [merge-where]] [honeysql.helpers :refer [merge-where]]
[bbbg.handlers.core :refer [page-response wrap-auth-required]] [ring.util.response :refer [content-type redirect response not-found]])
[ring.util.response :refer [content-type redirect response]] (:import java.util.UUID))
[bbbg.views.flash :as flash]))
(defn- attendees-page [{:keys [attendees q]}] (defn- attendees-page [{:keys [attendees q edit-notes]}]
[:div [:div
[:form.search-form {:method :get :action "/attendees"} [:form.search-form {:method :get :action "/attendees"}
[:input {:type "search" [:input {:type "search"
@ -27,25 +29,51 @@
[:th "Discord Name"] [:th "Discord Name"]
[:th "Events RSVPd"] [:th "Events RSVPd"]
[:th "Events Attended"] [:th "Events Attended"]
[:th "No-Shows"]]] [:th "No-Shows"]
[:th "Notes"]]]
[:tbody [:tbody
(for [attendee attendees] (for [attendee attendees
:let [id (::attendee/id attendee)]]
[:tr [:tr
[:td (::attendee/meetup-name attendee)] [:td (::attendee/meetup-name attendee)]
[:td (::attendee/discord-name attendee)] [:td (::attendee/discord-name attendee)]
[:td (:events-rsvpd attendee)] [:td (:events-rsvpd attendee)]
[:td (:events-attended attendee)] [:td (:events-attended attendee)]
[:td (:no-shows attendee)]])]]]) [:td (:no-shows attendee)]
(if (= edit-notes id)
[:td
[:form.organizer-notes {:method :post
:action (str "/attendees/" id "/notes")}
[:input {:type :text :name "notes"
:value (::attendee/organizer-notes attendee)}]
[:input {:type "Submit" :value "Save Notes"}]]]
[:td
(::attendee/organizer-notes attendee)
[:a {:href (str "/attendees?edit-notes=" id)}
"Edit Notes"]])])]]])
(defn attendees-routes [{:keys [db]}] (defn attendees-routes [{:keys [db]}]
(routes (routes
(wrap-auth-required (wrap-auth-required
(routes (routes
(GET "/attendees" [q] (GET "/attendees" [q edit-notes]
(let [attendees (db/list db (cond-> (db.attendee/with-stats) (let [attendees (db/list db (cond-> (db.attendee/with-stats)
q (db.attendee/search q)))] q (db.attendee/search q)))
edit-notes (some-> edit-notes UUID/fromString)]
(page-response (attendees-page {:attendees attendees (page-response (attendees-page {:attendees attendees
:q q})))))) :q q
:edit-notes edit-notes}))))
(POST "/attendees/:id/notes" [id :<< as-uuid notes]
(if (seq (db/update! db
:attendee
{::attendee/organizer-notes notes}
[:= :id id]))
(-> (redirect "/attendees")
(flash/add-flash
#:flash{:type :success
:message "Notes updated successfully"}))
(not-found "Attendee not found")))))
(GET "/attendees.json" [q event_id attended] (GET "/attendees.json" [q event_id attended]
(let [results (let [results