diff --git a/events/buttons/reject_event.py b/events/buttons/reject_event.py index 0b58c14..72b77ae 100644 --- a/events/buttons/reject_event.py +++ b/events/buttons/reject_event.py @@ -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 @@ -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"]) diff --git a/events/views/reject_event.py b/events/views/reject_event.py new file mode 100644 index 0000000..f11baa1 --- /dev/null +++ b/events/views/reject_event.py @@ -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 + ] + ) + diff --git a/utils/slack.py b/utils/slack.py index ae45be5..bc4afa6 100644 --- a/utils/slack.py +++ b/utils/slack.py @@ -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 @@ -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) diff --git a/views/reject_event.py b/views/reject_event.py new file mode 100644 index 0000000..0322818 --- /dev/null +++ b/views/reject_event.py @@ -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 +} \ No newline at end of file