|
| 1 | +from enum import IntEnum |
| 2 | +from typing import MutableMapping |
| 3 | + |
| 4 | +from pybot.endpoints.slack.utils import MENTOR_CHANNEL |
| 5 | + |
| 6 | +from .block_action import BlockAction |
| 7 | + |
| 8 | + |
| 9 | +class VolunteerBlockIndex(IntEnum): |
| 10 | + SKILLSET_OPTIONS = 2 |
| 11 | + SELECTED_SKILLSETS = 3 |
| 12 | + SUBMIT = 5 |
| 13 | + |
| 14 | + |
| 15 | +class MentorVolunteer(BlockAction): |
| 16 | + def __init__(self, raw_action: MutableMapping): |
| 17 | + super().__init__(raw_action) |
| 18 | + |
| 19 | + if "original_message" not in self: |
| 20 | + self["original_message"] = {} |
| 21 | + |
| 22 | + @property |
| 23 | + def skillsets(self) -> [str]: |
| 24 | + if self.skillset_fields: |
| 25 | + return [field["text"] for field in self.skillset_fields] |
| 26 | + return [] |
| 27 | + |
| 28 | + @property |
| 29 | + def skillset_fields(self) -> list: |
| 30 | + return self.blocks[VolunteerBlockIndex.SELECTED_SKILLSETS].get("fields", []) |
| 31 | + |
| 32 | + def add_skillset(self, skillset: str) -> None: |
| 33 | + """ |
| 34 | + Appends the new skillset to the displayed skillsets |
| 35 | + """ |
| 36 | + if skillset not in self.skillsets: |
| 37 | + new_field = {"type": "plain_text", "text": skillset, "emoji": True} |
| 38 | + self.blocks[VolunteerBlockIndex.SELECTED_SKILLSETS].setdefault( |
| 39 | + "fields", [] |
| 40 | + ).append(new_field) |
| 41 | + |
| 42 | + def clear_skillsets(self) -> None: |
| 43 | + if self.skillset_fields: |
| 44 | + del self.blocks[VolunteerBlockIndex.SELECTED_SKILLSETS]["fields"] |
| 45 | + |
| 46 | + def validate_self(self): |
| 47 | + if not self.skillsets: |
| 48 | + return False |
| 49 | + |
| 50 | + self.clear_errors() |
| 51 | + return True |
| 52 | + |
| 53 | + def add_errors(self) -> None: |
| 54 | + submit_attachment = { |
| 55 | + "text": ":warning: Please select at least one area. :warning:", |
| 56 | + "color": "danger", |
| 57 | + } |
| 58 | + self.attachments = [submit_attachment] |
| 59 | + |
| 60 | + def airtable_error(self, airtable_response) -> None: |
| 61 | + error_attachment = { |
| 62 | + "text": ( |
| 63 | + f"Something went wrong.\n" |
| 64 | + f'Error Type:{airtable_response["error"]["type"]}\n' |
| 65 | + f'Error Message: {airtable_response["error"]["message"]}' |
| 66 | + ), |
| 67 | + "color": "danger", |
| 68 | + } |
| 69 | + self.attachments = [error_attachment] |
| 70 | + |
| 71 | + def on_submit_success(self): |
| 72 | + done_blocks = [ |
| 73 | + {"type": "section", "text": {"type": "mrkdwn", "text": success_message}}, |
| 74 | + { |
| 75 | + "type": "actions", |
| 76 | + "block_id": "submission", |
| 77 | + "elements": [ |
| 78 | + { |
| 79 | + "type": "button", |
| 80 | + "action_id": "cancel_btn", |
| 81 | + "text": {"type": "plain_text", "text": "Dismiss"}, |
| 82 | + "value": "dismiss", |
| 83 | + } |
| 84 | + ], |
| 85 | + }, |
| 86 | + ] |
| 87 | + self.blocks = done_blocks |
| 88 | + |
| 89 | + |
| 90 | +success_message = ( |
| 91 | + "Thank you for signing up to be a mentor for Operation Code! You should have been automatically " |
| 92 | + f"added to the <#{MENTOR_CHANNEL}|mentors-internal> channel. There is a bot that posts in that " |
| 93 | + "channel when someone signs up for a 30 minute session with a mentor. If the skillsets they request " |
| 94 | + "match the ones you listed when you signed up, you'll be notified in the thread. Click the green " |
| 95 | + "button to claim them and reach out via DM to schedule a slack call. There are also a few pinned " |
| 96 | + f"items in that channel that may be helpful. If you have any questions, please DM <@aaron-s|aaron-s>.\n\n" |
| 97 | + "We don't currently have a formal long term mentorship program, but if you feel like continuing to " |
| 98 | + "keep in contact\n\n" |
| 99 | + "with any members you speak to, that's perfectly fine. " |
| 100 | + "Thank you for signing up!" |
| 101 | +) |
0 commit comments