]> git.cworth.org Git - turbot/commitdiff
Introduce a new modal view when the user clicks the "New Hunt" button
authorCarl Worth <cworth@cworth.org>
Wed, 14 Oct 2020 04:28:10 +0000 (21:28 -0700)
committerCarl Worth <cworth@cworth.org>
Wed, 14 Oct 2020 04:31:35 +0000 (21:31 -0700)
This modal doesn't yet _do_ anything but it shows the basic idea of how
we'll be collecting data.

turbot/actions.py
turbot/views.py

index f9dc83dd0caf8a59f263aead9f1ab79bef596cd4..c68de14a850bc269296f4d0d486a030056c307d1 100644 (file)
@@ -1,6 +1,11 @@
+import turbot.views
+
 def new_hunt(turb, payload):
 
     print("In new_hunt function")
+    view = turbot.views.new_hunt()
+    turb.slack_client.views_open(trigger_id=payload['trigger_id'],
+                                 view=view)
 
     return {
         'statusCode': 200,
index 2acc474579cc250378639d3307a607c3d9d6f928..fdd5eeb64e6d1794adce6799cdf2ec2a0963e009 100644 (file)
@@ -29,6 +29,23 @@ def button(label, name):
         "value": name
     }
 
+def input(label, name, placeholder):
+    return {
+        "type": "input",
+        "element": {
+            "type": "plain_text_input",
+            "action_id": name,
+            "placeholder": {
+                "type": "plain_text",
+                "text": placeholder,
+            }
+        },
+        "label": {
+            "type": "plain_text",
+            "text": label
+        }
+    }
+
 def hunt_block(hunt):
     text = "{}: <#{}>".format(hunt['name'], hunt['channel'])
     return section(text_block(text))
@@ -51,3 +68,17 @@ def home(turb, user_id, body):
             actions(button("New hunt", "new_hunt"))
         ]
     }
+
+def new_hunt():
+    """Returns a view to be published as the new_hunt modal"""
+
+    return {
+        "type": "modal",
+        "title": { "type": "plain_text", "text": "New Hunt" },
+        "submit": { "type": "plain_text", "text": "Create" },
+        "blocks": [
+            input("Hunt name", "name", "Name of the hunt"),
+            input("Hunt ID", "slug", "Short prefix for hunt (no spaces)"),
+            input("Hunt URL", "url", "External URL of hunt")
+        ]
+    }