Skip to content

Commit

Permalink
feat: add summer and competition hour categories
Browse files Browse the repository at this point in the history
  • Loading branch information
rutmanz committed Sep 11, 2023
1 parent aabd152 commit 6a8baf8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
37 changes: 23 additions & 14 deletions src/handlers/accept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions src/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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)
Expand All @@ -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)
Expand Down
22 changes: 21 additions & 1 deletion src/views/new_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 6a8baf8

Please sign in to comment.