From aa34325acf1a928ec83369694ebcccb985247020 Mon Sep 17 00:00:00 2001 From: KjellBerlin Date: Mon, 23 Sep 2024 12:13:48 +0200 Subject: [PATCH] Add unassign button --- .../core/slack/SlackMessageService.kt | 73 +++++++++++++++++++ .../com/carbonara/core/slack/SlackService.kt | 1 + 2 files changed, 74 insertions(+) diff --git a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt index 6213719..075a22c 100644 --- a/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt +++ b/src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt @@ -81,6 +81,7 @@ class SlackMessageService { OrderStatus.DELIVERY_IN_PROGRESS -> updateOrderMessageToDeliveryInProgress(params) OrderStatus.DELIVERED -> updateOrderMessageToDelivered(params) OrderStatus.CANCELLED -> updateOrderMessageToCancelled(params) + OrderStatus.FINDING_AVAILABLE_RIDER -> updateOrderMessageToUnassigned(params) else -> throw IllegalArgumentException("Cannot update slack message based on order status ${params.orderStatus}") } @@ -141,6 +142,11 @@ class SlackMessageService { value(params.orderId) actionId("cancelled") } + button { + text("UNASSIGN", emoji = true) + value(params.orderId) + actionId("unassign") + } } divider() } @@ -195,6 +201,11 @@ class SlackMessageService { value(params.orderId) actionId("cancelled") } + button { + text("UNASSIGN", emoji = true) + value(params.orderId) + actionId("unassign") + } } divider() } @@ -249,6 +260,11 @@ class SlackMessageService { value(params.orderId) actionId("cancelled") } + button { + text("UNASSIGN", emoji = true) + value(params.orderId) + actionId("unassign") + } } divider() } @@ -303,6 +319,63 @@ class SlackMessageService { value(params.orderId) actionId("cancelled") } + button { + text("UNASSIGN", emoji = true) + value(params.orderId) + actionId("unassign") + } + } + divider() + } + } + } + + fun updateOrderMessageToUnassigned( + params: SlackMessageParams + ): ChatUpdateResponse? { + + val slack = Slack.getInstance() + return slack.methods(slackToken).chatUpdate { req -> req + .channel(slackChannel) + .ts(params.timeStamp) + .blocks { + section { + fields { + markdownText("*Customer Name:*\n${params.customerName}") + markdownText("*OrderId:*\n${params.orderId}") + } + } + section { + fields { + markdownText("*Address:*\n${params.address}\n${params.googleMapsLink}") + markdownText("*Products:*\n${params.productNames.joinToString(", ")}") + } + } + actions { + button { + text("ACCEPT", emoji = true) + style("primary") + value(params.orderId) + actionId("accept") + } + button { + text("DELIVERY IN PROGRESS", emoji = true) + style("primary") + value(params.orderId) + actionId("delivery_in_progress") + } + button { + text("DELIVERED", emoji = true) + style("primary") + value(params.orderId) + actionId("delivered") + } + button { + text("CANCELLED", emoji = true) + style("danger") + value(params.orderId) + actionId("cancelled") + } } divider() } diff --git a/src/main/kotlin/com/carbonara/core/slack/SlackService.kt b/src/main/kotlin/com/carbonara/core/slack/SlackService.kt index c882038..ae1459f 100644 --- a/src/main/kotlin/com/carbonara/core/slack/SlackService.kt +++ b/src/main/kotlin/com/carbonara/core/slack/SlackService.kt @@ -43,6 +43,7 @@ class SlackService( "delivery_in_progress" -> OrderStatus.DELIVERY_IN_PROGRESS "delivered" -> OrderStatus.DELIVERED "cancelled" -> OrderStatus.CANCELLED + "unassign" -> OrderStatus.FINDING_AVAILABLE_RIDER else -> throw IllegalArgumentException("Invalid slack order status: $slackOrderStatus") } }