about summary refs log tree commit diff
path: root/users/grfn
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2021-12-19T18·39-0500
committerclbot <clbot@tvl.fyi>2021-12-19T18·42+0000
commit736ef8ce4101245a2fa4b05a76103d37fd829903 (patch)
tree05ad68285eeeefaacbe0f5d0047949cb067a905a /users/grfn
parent562236085b79b3fe793d9f02fdcbba9480c6a5ee (diff)
feat(grfn/bbbg): Display + allow editing attendee notes r/3312
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
Diffstat (limited to 'users/grfn')
-rw-r--r--users/grfn/bbbg/src/bbbg/handlers/attendees.clj60
1 files changed, 44 insertions, 16 deletions
diff --git a/users/grfn/bbbg/src/bbbg/handlers/attendees.clj b/users/grfn/bbbg/src/bbbg/handlers/attendees.clj
index b6846c1f3c44..3a5b49900476 100644
--- a/users/grfn/bbbg/src/bbbg/handlers/attendees.clj
+++ b/users/grfn/bbbg/src/bbbg/handlers/attendees.clj
@@ -5,14 +5,16 @@
    [bbbg.db.attendee :as db.attendee]
    [bbbg.db.event :as db.event]
    [bbbg.event :as event]
+   [bbbg.handlers.core :refer [page-response wrap-auth-required]]
+   [bbbg.views.flash :as flash]
    [cheshire.core :as json]
+   [compojure.coercions :refer [as-uuid]]
    [compojure.core :refer [GET POST routes]]
    [honeysql.helpers :refer [merge-where]]
-   [bbbg.handlers.core :refer [page-response wrap-auth-required]]
-   [ring.util.response :refer [content-type redirect response]]
-   [bbbg.views.flash :as flash]))
+   [ring.util.response :refer [content-type redirect response not-found]])
+  (:import java.util.UUID))
 
-(defn- attendees-page [{:keys [attendees q]}]
+(defn- attendees-page [{:keys [attendees q edit-notes]}]
   [:div
    [:form.search-form {:method :get :action "/attendees"}
     [:input {:type "search"
@@ -27,25 +29,51 @@
       [:th "Discord Name"]
       [:th "Events RSVPd"]
       [:th "Events Attended"]
-      [:th "No-Shows"]]]
+      [:th "No-Shows"]
+      [:th "Notes"]]]
     [:tbody
-     (for [attendee attendees]
+     (for [attendee attendees
+           :let [id (::attendee/id attendee)]]
        [:tr
         [:td (::attendee/meetup-name attendee)]
         [:td (::attendee/discord-name attendee)]
         [:td (:events-rsvpd 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]}]
   (routes
    (wrap-auth-required
     (routes
-     (GET "/attendees" [q]
+     (GET "/attendees" [q edit-notes]
        (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
-                                         :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]
      (let [results
@@ -55,12 +83,12 @@
                 (if q
                   (db.attendee/search q)
                   {:select [:attendee.*] :from [:attendee]})
-              event_id (db.attendee/for-event event_id)
-              (some? attended)
-              (merge-where
-               (case attended
-                 "true" :attended
-                 "false" [:or [:= :attended nil] [:not :attended]]))))]
+                event_id (db.attendee/for-event event_id)
+                (some? attended)
+                (merge-where
+                 (case attended
+                   "true" :attended
+                   "false" [:or [:= :attended nil] [:not :attended]]))))]
        (-> {:results results}
            json/generate-string
            response