Skip to content

Commit

Permalink
add event rejection reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
transcental committed Dec 1, 2024
1 parent a8dc80b commit 9dbd59d
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 34 deletions.
37 changes: 3 additions & 34 deletions events/buttons/reject_event.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from slack_sdk import WebClient

from utils.env import env
from views.app_home import get_home
from views.reject_event import get_reject_event_modal

from typing import Any, Callable

Expand All @@ -18,37 +18,6 @@ def handle_reject_event_btn(ack: Callable, body: dict[str, Any], client: WebClie
)
return

value = body["actions"][0]["value"]
event_id = body["actions"][0]["value"]

event = env.airtable.get_event(value)

if not event:
client.chat_postEphemeral(
user=body["user"]["id"],
channel=body["user"]["id"],
text=f"Event with id `{value}` not found.",
)
return

if event["fields"].get("Canceled", False):
client.chat_postEphemeral(
user=body["user"]["id"],
channel=body["user"]["id"],
text=f"Event with id `{value}` has already been rejected.",
)
return

event = env.airtable.update_event(value, **{"Canceled": True})

client.chat_postMessage(
user=body["user"]["id"],
channel=env.slack_approval_channel,
text=f"<@{user_id}> rejected {event['fields']['Title']} for <@{event['fields']['Leader Slack ID']}>.",
)

client.chat_postMessage(
channel=event["fields"]["Leader Slack ID"],
text=f"Your event {event['fields']['Title']} has been rejected by <@{user_id}>. They should have sent you a message about this, please reach out to them if they've not.",
)

client.views_publish(user_id=user_id, view=get_home(user_id, client))
client.views_open(user_id=user_id, view=get_reject_event_modal(event_id), trigger_id=body["trigger_id"])
66 changes: 66 additions & 0 deletions events/views/reject_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from typing import Any, Callable
from slack_sdk import WebClient

from utils.env import env


def handle_reject_event_view(ack: Callable, body: dict[str, Any], client: WebClient):
ack()
view = body["view"]
message = view["state"]["values"]["message"]["message"]["rich_text_value"]
event_id = view["private_metadata"]

event = env.airtable.get_event(event_id)

if not event:
client.chat_postEphemeral(
user=body["user"]["id"],
channel=body["user"]["id"],
text=f"Event with id `{event_id}` not found.",
)
return

if event["fields"].get("Canceled", False):
client.chat_postEphemeral(
user=body["user"]["id"],
channel=body["user"]["id"],
text=f"Event with id `{event_id}` has already been rejected.",
)
return

event = env.airtable.update_event(event_id, **{"Canceled": True})

client.chat_postMessage(
channel=env.slack_approval_channel,
text=f"<@{body['user']['id']}> rejected {event['fields']['Title']} for <@{event['fields']['Leader Slack ID']}> with the following reason.",
blocks=[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"<@{body['user']['id']}> rejected {event['fields']['Title']} for <@{event['fields']['Leader Slack ID']}> with the following reason."
}
}, {
"type": "divider",
},
message
]
)

client.chat_postMessage(
channel=event["fields"]["Leader Slack ID"],
text=f"Your event {event['fields']['Title']} has been rejected by <@{body['user']['id']}> with the following reason. Please reach out to them if you have any questions or need help.",
blocks=[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"Your event {event['fields']['Title']} has been rejected by <@{body['user']['id']}> :(\nPlease reach out to them if you have any questions or need help."
}
}, {
"type": "divider",
},
message
]
)

6 changes: 6 additions & 0 deletions utils/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from events.buttons.edit_event import handle_edit_event_btn
from events.commands.create_event import handle_create_event_cmd
from events.views.create_event import handle_create_event_view
from events.views.reject_event import handle_reject_event_view
from events.views.edit_event import handle_edit_event_view
from events.buttons.propose_event import handle_propose_event_btn
from events.buttons.approve_event import handle_approve_event_btn
Expand Down Expand Up @@ -35,6 +36,11 @@ def edit_event_view(ack: Callable, body: dict[str, Any], client: WebClient):
handle_edit_event_view(ack, body, client)


@app.view("reject_event")
def reject_event_view(ack: Callable, body: dict[str, Any], client: WebClient):
handle_reject_event_view(ack, body, client)


@app.action("approve-event")
def approve_event(ack: Callable, body: dict[str, Any], client: WebClient):
handle_approve_event_btn(ack, body, client)
Expand Down
62 changes: 62 additions & 0 deletions views/reject_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from utils.env import env

def get_reject_event_modal(event_id: str):
event = env.airtable.get_event(event_id)
if not event:
return {
"type": "modal",
"title": {
"type": "plain_text",
"text": "Error",
"emoji": True
},
"close": {
"type": "plain_text",
"text": "Close",
"emoji": True
},
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"Event with id `{event_id}` not found."
}
}
]
}
return {
"type": "modal",
"callback_id": "reject_event",
"title": {
"type": "plain_text",
"text": "Reject Event",
"emoji": True
},
"submit": {
"type": "plain_text",
"text": "Reject",
"emoji": True
},
"close": {
"type": "plain_text",
"text": "Cancel",
"emoji": True
},
"blocks": [
{
"type": "input",
"block_id": "message",
"element": {
"type": "rich_text_input",
"action_id": "message"
},
"label": {
"type": "plain_text",
"text": f"Why are you rejecting \"{event['fields']['Title']}\"?",
"emoji": True
}
}
],
"private_metadata": event_id
}

0 comments on commit 9dbd59d

Please sign in to comment.