Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add summer and competition hour categories #2

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, body.view.state.values.type_selector.selector.selected_option?.value as keyof typeof submission_prefixes ?? "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
66 changes: 61 additions & 5 deletions src/views/respond.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import type { ModalView } from "@slack/bolt";
import { formatDuration, sanitizeCodeblock } from "../messages";

export function getRespondMessageModal(type: "Accept"|"Reject", name:string, hours:number, activity:string, request_id:string): ModalView {
export function getRespondMessageModal(type: "Accept" | "Reject", name: string, hours: number, activity: string, request_id: string): ModalView {
const callback_id = `${type.toLowerCase()}_modal`
return {
const data:ModalView = {
type: "modal",
private_metadata: request_id,
callback_id: callback_id,
title: {
type: "plain_text",
text: type+"Time Request",
text: type + "Time Request",
emoji: true
},
submit: {
type: "plain_text",
text: type+" and Send",
text: type + " and Send",
emoji: true
},
close: {
Expand Down Expand Up @@ -43,10 +43,66 @@ export function getRespondMessageModal(type: "Accept"|"Reject", name:string, hou
},
label: {
type: "plain_text",
text: type+" and Send Message",
text: type + " and Send Message",
emoji: true
}
}
]
}
if (type == "Accept") {
data.blocks.push({
block_id: "type_selector",
type: "input",
label: {
type: "plain_text",
text: "Type of submission",
emoji: true
},
element: {
action_id:"selector",
type: "static_select",
initial_option: {
text: {
type: "plain_text",
text: "Regular",
emoji: true
},
value: "regular"
},
placeholder: {
"type": "plain_text",
"emoji": true,
text: "Select a type"
},
// options: Object.values(metrics),
options: [
{
text: {
type: "plain_text",
text: "Regular",
emoji: true
},
value: "regular"
},
{
text: {
type: "plain_text",
text: "Summer ☀️",
emoji: true
},
value: "summer"
},
{
text: {
type: "plain_text",
text: "Competition",
emoji: true
},
value: "competition"
}
],
}
})
}
return data
}
Loading