diff --git a/src/handlers/accept.ts b/src/handlers/accept.ts index db34718..83d4d64 100644 --- a/src/handlers/accept.ts +++ b/src/handlers/accept.ts @@ -24,29 +24,38 @@ export async function handleAcceptModal({ ack, body, view, client }: SlackViewMi const time_request = data.timeRequests[request_id] await client.chat.postMessage({ channel: time_request.userId, text: getAcceptedDm(body.user.id, time_request.time, time_request.activity, body.view.state.values.message.input.value) }) - await handleAccept(time_request, body, client) + await handleAccept(time_request, body, client, "regular") delete data.timeRequests[request_id] saveData() } - -export async function handleAcceptButton({ ack, body, action, client }: ButtonActionMiddlewareArgs & AllMiddlewareArgs) { - await ack() - - const request_id = action.value - const time_request = data.timeRequests[request_id] +export function getAcceptButtonHandler(prefix:keyof typeof submission_prefixes) { + return async function({ ack, body, action, client }: ButtonActionMiddlewareArgs & AllMiddlewareArgs) { + await ack() + + const request_id = action.value + const time_request = data.timeRequests[request_id] + + await client.chat.postMessage({ channel: time_request.userId, text: getAcceptedDm(body.user.id, time_request.time, time_request.activity) }) + await handleAccept(time_request, body, client, prefix) - await client.chat.postMessage({ channel: time_request.userId, text: getAcceptedDm(body.user.id, time_request.time, time_request.activity) }) - await handleAccept(time_request, body, client) - - delete data.timeRequests[request_id] - saveData() + delete data.timeRequests[request_id] + saveData() + } } -async function handleAccept(time_request:TimeRequest, body:BlockAction|ViewSubmitAction, client:WebClient) { + + +const submission_prefixes = { + "regular": "external: ", + "summer": "summer: ", + "competition": "comp: " +} +async function handleAccept(time_request:TimeRequest, body:BlockAction|ViewSubmitAction, client:WebClient, type:keyof typeof submission_prefixes) { try { - await addHours(time_request.name, time_request.time, time_request.activity) + + await addHours(time_request.name, time_request.time, submission_prefixes[type]+time_request.activity) } catch { console.error("Failed to add hours with request", time_request) return diff --git a/src/handlers/index.ts b/src/handlers/index.ts index d2cfde3..9afc0e5 100644 --- a/src/handlers/index.ts +++ b/src/handlers/index.ts @@ -1,5 +1,5 @@ import type { App } from "@slack/bolt"; -import { handleAcceptButton, handleAcceptMessageButton, handleAcceptModal } from "./accept"; +import { getAcceptButtonHandler, handleAcceptMessageButton, handleAcceptModal } from "./accept"; import { handleLeaderboardAction, handleAppHomeOpened } from "./app_home"; import { handleGraphCommand } from "./graph"; import { handleLogCommand, handleLogModal, handleLogShortcut } from "./log"; @@ -8,7 +8,7 @@ import { handleRejectButton, handleRejectModal } from "./reject"; import { handleOpenSettingsModal, handleSettingsSave } from "./settings"; import { handleVoidCommand } from "./void"; -export function register_listeners(app:App) { +export function register_listeners(app: App) { // Commands and Shortcuts app.command('/log', handleLogCommand) app.command('/graph', handleGraphCommand) @@ -17,15 +17,17 @@ export function register_listeners(app:App) { app.shortcut('log_hours', handleLogShortcut) // Buttons - app.action("accept", handleAcceptButton) + app.action("accept", getAcceptButtonHandler("regular")) + app.action("accept_summer", getAcceptButtonHandler("summer")) + app.action("accept_comp", getAcceptButtonHandler("competition")) app.action("accept_msg", handleAcceptMessageButton) app.action("reject", handleRejectButton) app.action("open_settings_modal", handleOpenSettingsModal) app.action("jump_url", async ({ ack }) => { await ack() }) - + // Inputs app.action("selected_metric", handleLeaderboardAction) - + // Modals app.view("reject_modal", handleRejectModal) app.view("accept_modal", handleAcceptModal) diff --git a/src/views/new_request.ts b/src/views/new_request.ts index 25123b2..484ef9c 100644 --- a/src/views/new_request.ts +++ b/src/views/new_request.ts @@ -26,12 +26,32 @@ export function getRequestBlocks(uid: string, hrs: number, activity: string, req text: { type: "plain_text", emoji: true, - text: "Add to Sheet" + text: "Accept" }, style: "primary", action_id: "accept", value: request_id }, + { + type: "button", + text: { + type: "plain_text", + emoji: true, + text: "Accept Summer ☀️" + }, + action_id: "accept_summer", + value: request_id + }, + { + type: "button", + text: { + type: "plain_text", + emoji: true, + text: "Accept Competition" + }, + action_id: "accept_comp", + value: request_id + }, { type: "button", text: {