mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Option to Notify Workspace Owner When Usage Limit is Reached (#16969)
## Summary - Replace the manual `/notify-owner` flow with an inline confirmation prompt when a usage-based workspace member hits a credits-depleted limit. - Fetch the current workspace role from the live ChatGPT `accounts/check/v4-2023-04-27` endpoint so owner/member behavior matches the desktop and web clients. - Keep owner, member, and spend-cap messaging distinct so we only offer the owner nudge when the workspace is actually out of credits. ## What Changed - `backend-client` - Added a typed fetch for the current account role from `accounts/check`. - Mapped backend role values into a Rust workspace-role enum. - `app-server` and protocol - Added `workspaceRole` to `account/read` and `account/updated`. - Derived `isWorkspaceOwner` from the live role, with a fallback to the cached token claim when the role fetch is unavailable. - `tui` - Removed the explicit `/notify-owner` slash command. - When a member is blocked because the workspace is out of credits, the error now prompts: - `Your workspace is out of credits. Request more from your workspace owner? [y/N]` - Choosing `y` sends the existing owner-notification request. - Choosing `n`, pressing `Esc`, or accepting the default selection dismisses the prompt without sending anything. - Selection popups now honor explicit item shortcuts, which is how the `y` / `n` interaction is wired. ## Reviewer Notes - The main behavior change is scoped to usage-based workspace members whose workspace credits are depleted. - Spend-cap reached should not show the owner-notification prompt. - Owners and admins should continue to see `/usage` guidance instead of the member prompt. - The live role fetch is best-effort; if it fails, we fall back to the existing token-derived ownership signal. ## Testing - Manual verification - Workspace owner does not see the member prompt. - Workspace member with depleted credits sees the confirmation prompt and can send the nudge with `y`. - Workspace member with spend cap reached does not see the owner-notification prompt. ### Workspace member out of usage https://github.com/user-attachments/assets/341ac396-eff4-4a7f-bf0c-60660becbea1 ### Workspace owner <img width="1728" height="1086" alt="Screenshot 2026-04-09 at 11 48 22 AM" src="https://github.com/user-attachments/assets/06262a45-e3fc-4cc4-8326-1cbedad46ed6" />
This commit is contained in:
1 parent
36712d8546
commit
9f2a585153
82 files changed
+3233
-60
No files matched your search
@@ -67,6 +67,7 @@ use crate::terminal_title::clear_terminal_title;
|
||||
use crate::terminal_title::set_terminal_title;
|
||||
use crate::text_formatting::proper_join;
|
||||
use crate::version::CODEX_CLI_VERSION;
|
||||
use codex_app_server_protocol::AddCreditsNudgeEmailResult as AppServerAddCreditsNudgeEmailResult;
|
||||
use codex_app_server_protocol::AppSummary;
|
||||
use codex_app_server_protocol::CodexErrorInfo as AppServerCodexErrorInfo;
|
||||
use codex_app_server_protocol::CollabAgentState as AppServerCollabAgentState;
|
||||
@@ -91,6 +92,7 @@ use codex_app_server_protocol::Turn;
|
||||
use codex_app_server_protocol::TurnCompletedNotification;
|
||||
use codex_app_server_protocol::TurnPlanStepStatus;
|
||||
use codex_app_server_protocol::TurnStatus;
|
||||
use codex_app_server_protocol::WorkspaceRole as AppServerWorkspaceRole;
|
||||
use codex_chatgpt::connectors;
|
||||
use codex_config::types::ApprovalsReviewer;
|
||||
use codex_config::types::Notifications;
|
||||
@@ -133,6 +135,7 @@ use codex_protocol::models::local_image_label_text;
|
||||
use codex_protocol::parse_command::ParsedCommand;
|
||||
use codex_protocol::plan_tool::PlanItemArg as UpdatePlanItemArg;
|
||||
use codex_protocol::plan_tool::StepStatus as UpdatePlanItemStatus;
|
||||
use codex_protocol::protocol::AddCreditsNudgeEmailStatus;
|
||||
#[cfg(test)]
|
||||
use codex_protocol::protocol::AgentMessageDeltaEvent;
|
||||
#[cfg(test)]
|
||||
@@ -191,6 +194,7 @@ use codex_protocol::protocol::RateLimitSnapshot;
|
||||
use codex_protocol::protocol::ReviewRequest;
|
||||
use codex_protocol::protocol::ReviewTarget;
|
||||
use codex_protocol::protocol::SkillMetadata as ProtocolSkillMetadata;
|
||||
use codex_protocol::protocol::SpendControlSnapshot;
|
||||
#[cfg(test)]
|
||||
use codex_protocol::protocol::StreamErrorEvent;
|
||||
use codex_protocol::protocol::TerminalInteractionEvent;
|
||||
@@ -555,6 +559,8 @@ pub(crate) struct ChatWidgetInit {
|
||||
pub(crate) feedback: codex_feedback::CodexFeedback,
|
||||
pub(crate) is_first_run: bool,
|
||||
pub(crate) status_account_display: Option<StatusAccountDisplay>,
|
||||
pub(crate) initial_workspace_role: Option<AppServerWorkspaceRole>,
|
||||
pub(crate) initial_is_workspace_owner: Option<bool>,
|
||||
pub(crate) initial_plan_type: Option<PlanType>,
|
||||
pub(crate) model: Option<String>,
|
||||
pub(crate) startup_tooltip_override: Option<String>,
|
||||
@@ -601,6 +607,32 @@ enum RateLimitErrorKind {
|
||||
Generic,
|
||||
}
|
||||
|
||||
pub(crate) const CODEX_USAGE_SETTINGS_URL: &str = "https://chatgpt.com/codex/settings/usage";
|
||||
const WORKSPACE_OWNER_NOTIFICATION_PROMPT: &str =
|
||||
"Your workspace is out of credits. Request more from your workspace owner? [y/N]";
|
||||
const WORKSPACE_OWNER_NOTIFICATION_TITLE: &str = "Request more credits from your workspace owner?";
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum UsageBasedWorkspaceRateLimitState {
|
||||
OwnerCreditsDepleted,
|
||||
OwnerSpendCapReached,
|
||||
MemberCreditsDepleted,
|
||||
MemberSpendCapReached,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum UsageBasedWorkspaceBlockKind {
|
||||
CreditsDepleted,
|
||||
SpendCapReached,
|
||||
}
|
||||
|
||||
fn is_usage_based_workspace_plan(plan_type: PlanType) -> bool {
|
||||
matches!(
|
||||
plan_type,
|
||||
PlanType::SelfServeBusinessUsageBased | PlanType::EnterpriseCbpUsageBased
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn core_rate_limit_error_kind(info: &CoreCodexErrorInfo) -> Option<RateLimitErrorKind> {
|
||||
match info {
|
||||
@@ -756,6 +788,8 @@ pub(crate) struct ChatWidget {
|
||||
/// The currently active collaboration mask, if any.
|
||||
active_collaboration_mask: Option<CollaborationModeMask>,
|
||||
has_chatgpt_account: bool,
|
||||
workspace_role: Option<AppServerWorkspaceRole>,
|
||||
is_workspace_owner: Option<bool>,
|
||||
model_catalog: Arc<ModelCatalog>,
|
||||
session_telemetry: SessionTelemetry,
|
||||
session_header: SessionHeader,
|
||||
@@ -766,6 +800,8 @@ pub(crate) struct ChatWidget {
|
||||
refreshing_status_outputs: Vec<(u64, StatusHistoryHandle)>,
|
||||
next_status_refresh_request_id: u64,
|
||||
plan_type: Option<PlanType>,
|
||||
notify_workspace_owner_in_flight: bool,
|
||||
pending_workspace_owner_notification_prompt: bool,
|
||||
rate_limit_warnings: RateLimitWarningState,
|
||||
rate_limit_switch_prompt: RateLimitSwitchPromptState,
|
||||
adaptive_chunking: AdaptiveChunkingPolicy,
|
||||
@@ -2677,6 +2713,15 @@ impl ChatWidget {
|
||||
balance: credits.balance.clone(),
|
||||
});
|
||||
}
|
||||
if snapshot.spend_control.is_none() {
|
||||
snapshot.spend_control = self
|
||||
.rate_limit_snapshots_by_limit_id
|
||||
.get(&limit_id)
|
||||
.and_then(|display| display.spend_control.as_ref())
|
||||
.map(|spend_control| SpendControlSnapshot {
|
||||
reached: spend_control.reached,
|
||||
});
|
||||
}
|
||||
|
||||
self.plan_type = snapshot.plan_type.or(self.plan_type);
|
||||
|
||||
@@ -2745,6 +2790,7 @@ impl ChatWidget {
|
||||
} else {
|
||||
self.rate_limit_snapshots_by_limit_id.clear();
|
||||
}
|
||||
self.maybe_show_pending_workspace_owner_notification_prompt();
|
||||
self.refresh_status_line();
|
||||
}
|
||||
/// Finalize any active exec as failed and stop/clear agent-turn UI state.
|
||||
@@ -2787,15 +2833,34 @@ impl ChatWidget {
|
||||
}
|
||||
|
||||
fn on_error(&mut self, message: String) {
|
||||
self.on_error_with_hint(message, /*hint*/ None);
|
||||
}
|
||||
|
||||
fn on_error_with_hint(&mut self, message: String, hint: Option<String>) {
|
||||
self.submit_pending_steers_after_interrupt = false;
|
||||
self.finalize_turn();
|
||||
self.add_to_history(history_cell::new_error_event(message));
|
||||
self.add_to_history(history_cell::new_error_event_with_hint(message, hint));
|
||||
self.request_redraw();
|
||||
|
||||
// After an error ends the turn, try sending the next queued input.
|
||||
self.maybe_send_next_queued_input();
|
||||
}
|
||||
|
||||
fn on_rate_limit_error(&mut self, message: String) {
|
||||
if self.should_prefetch_rate_limits() {
|
||||
self.request_rate_limit_refresh();
|
||||
}
|
||||
let guidance = self.usage_based_workspace_rate_limit_error_guidance();
|
||||
let should_prompt_workspace_owner = self.should_prompt_workspace_owner_notification();
|
||||
let hint = guidance.as_ref().and_then(|(_, hint)| hint.clone());
|
||||
let message = guidance.map(|(message, _)| message).unwrap_or(message);
|
||||
self.on_error_with_hint(message, hint);
|
||||
if should_prompt_workspace_owner {
|
||||
self.pending_workspace_owner_notification_prompt = true;
|
||||
self.maybe_show_pending_workspace_owner_notification_prompt();
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_non_retry_error(
|
||||
&mut self,
|
||||
message: String,
|
||||
@@ -2812,7 +2877,7 @@ impl ChatWidget {
|
||||
match info {
|
||||
RateLimitErrorKind::ServerOverloaded => self.on_server_overloaded_error(message),
|
||||
RateLimitErrorKind::UsageLimit | RateLimitErrorKind::Generic => {
|
||||
self.on_error(message)
|
||||
self.on_rate_limit_error(message);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -4612,6 +4677,8 @@ impl ChatWidget {
|
||||
feedback,
|
||||
is_first_run,
|
||||
status_account_display,
|
||||
initial_workspace_role,
|
||||
initial_is_workspace_owner,
|
||||
initial_plan_type,
|
||||
model,
|
||||
startup_tooltip_override,
|
||||
@@ -4673,6 +4740,8 @@ impl ChatWidget {
|
||||
current_collaboration_mode,
|
||||
active_collaboration_mask,
|
||||
has_chatgpt_account,
|
||||
workspace_role: initial_workspace_role,
|
||||
is_workspace_owner: initial_is_workspace_owner,
|
||||
model_catalog,
|
||||
session_telemetry,
|
||||
session_header: SessionHeader::new(header_model),
|
||||
@@ -4683,6 +4752,8 @@ impl ChatWidget {
|
||||
refreshing_status_outputs: Vec::new(),
|
||||
next_status_refresh_request_id: 0,
|
||||
plan_type: initial_plan_type,
|
||||
notify_workspace_owner_in_flight: false,
|
||||
pending_workspace_owner_notification_prompt: false,
|
||||
rate_limit_warnings: RateLimitWarningState::default(),
|
||||
rate_limit_switch_prompt: RateLimitSwitchPromptState::default(),
|
||||
adaptive_chunking: AdaptiveChunkingPolicy::default(),
|
||||
@@ -5322,9 +5393,7 @@ impl ChatWidget {
|
||||
}
|
||||
SlashCommand::Status => {
|
||||
if self.should_prefetch_rate_limits() {
|
||||
let request_id = self.next_status_refresh_request_id;
|
||||
self.next_status_refresh_request_id =
|
||||
self.next_status_refresh_request_id.wrapping_add(1);
|
||||
let request_id = self.next_rate_limit_refresh_request_id();
|
||||
self.add_status_output(/*refreshing_rate_limits*/ true, Some(request_id));
|
||||
self.app_event_tx.send(AppEvent::RefreshRateLimits {
|
||||
origin: RateLimitRefreshOrigin::StatusCommand { request_id },
|
||||
@@ -6583,6 +6652,18 @@ impl ChatWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
ServerNotification::AddCreditsNudgeEmailCompleted(notification) => {
|
||||
let result = match notification.result {
|
||||
AppServerAddCreditsNudgeEmailResult::Sent => {
|
||||
Ok(AddCreditsNudgeEmailStatus::Sent)
|
||||
}
|
||||
AppServerAddCreditsNudgeEmailResult::CooldownActive => {
|
||||
Ok(AddCreditsNudgeEmailStatus::CooldownActive)
|
||||
}
|
||||
AppServerAddCreditsNudgeEmailResult::Failed { message } => Err(message),
|
||||
};
|
||||
self.finish_notify_workspace_owner(result);
|
||||
}
|
||||
ServerNotification::ThreadRealtimeSdp(notification) => {
|
||||
if !from_replay {
|
||||
self.on_realtime_conversation_sdp(notification.sdp);
|
||||
@@ -6991,7 +7072,7 @@ impl ChatWidget {
|
||||
self.on_server_overloaded_error(message)
|
||||
}
|
||||
RateLimitErrorKind::UsageLimit | RateLimitErrorKind::Generic => {
|
||||
self.on_error(message)
|
||||
self.on_rate_limit_error(message)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -7047,6 +7128,9 @@ impl ChatWidget {
|
||||
EventMsg::GetHistoryEntryResponse(ev) => self.handle_history_entry_response(ev),
|
||||
EventMsg::McpListToolsResponse(ev) => self.on_list_mcp_tools(ev),
|
||||
EventMsg::ListSkillsResponse(ev) => self.on_list_skills(ev),
|
||||
EventMsg::AddCreditsNudgeEmailResponse(ev) => {
|
||||
self.finish_notify_workspace_owner(ev.result);
|
||||
}
|
||||
EventMsg::SkillsUpdateAvailable => {
|
||||
self.submit_op(AppCommand::list_skills(
|
||||
Vec::new(),
|
||||
@@ -9586,19 +9670,268 @@ impl ChatWidget {
|
||||
self.plan_type
|
||||
}
|
||||
|
||||
pub(crate) fn current_is_workspace_owner(&self) -> Option<bool> {
|
||||
self.workspace_role
|
||||
.map(|role| {
|
||||
matches!(
|
||||
role,
|
||||
AppServerWorkspaceRole::AccountOwner | AppServerWorkspaceRole::AccountAdmin
|
||||
)
|
||||
})
|
||||
.or(self.is_workspace_owner)
|
||||
}
|
||||
|
||||
pub(crate) fn current_workspace_role(&self) -> Option<AppServerWorkspaceRole> {
|
||||
self.workspace_role
|
||||
}
|
||||
|
||||
pub(crate) fn has_chatgpt_account(&self) -> bool {
|
||||
self.has_chatgpt_account
|
||||
}
|
||||
|
||||
fn usage_based_workspace_rate_limit_state(&self) -> Option<UsageBasedWorkspaceRateLimitState> {
|
||||
let block_kind = self.usage_based_workspace_block_kind()?;
|
||||
let is_workspace_owner = self.current_is_workspace_owner()?;
|
||||
Some(match (is_workspace_owner, block_kind) {
|
||||
(true, UsageBasedWorkspaceBlockKind::CreditsDepleted) => {
|
||||
UsageBasedWorkspaceRateLimitState::OwnerCreditsDepleted
|
||||
}
|
||||
(true, UsageBasedWorkspaceBlockKind::SpendCapReached) => {
|
||||
UsageBasedWorkspaceRateLimitState::OwnerSpendCapReached
|
||||
}
|
||||
(false, UsageBasedWorkspaceBlockKind::CreditsDepleted) => {
|
||||
UsageBasedWorkspaceRateLimitState::MemberCreditsDepleted
|
||||
}
|
||||
(false, UsageBasedWorkspaceBlockKind::SpendCapReached) => {
|
||||
UsageBasedWorkspaceRateLimitState::MemberSpendCapReached
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn usage_based_workspace_block_kind(&self) -> Option<UsageBasedWorkspaceBlockKind> {
|
||||
let plan_type = self.plan_type?;
|
||||
if !is_usage_based_workspace_plan(plan_type) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let codex_snapshot = self.rate_limit_snapshots_by_limit_id.get("codex")?;
|
||||
let credits_depleted = codex_snapshot
|
||||
.credits
|
||||
.as_ref()
|
||||
.is_some_and(|credits| !credits.has_credits);
|
||||
let spend_control_reached = codex_snapshot
|
||||
.spend_control
|
||||
.as_ref()
|
||||
.map(|spend_control| spend_control.reached);
|
||||
|
||||
let blocked_state = match (credits_depleted, spend_control_reached) {
|
||||
(true, _) => Some(true),
|
||||
(false, Some(true)) => Some(false),
|
||||
(false, Some(false)) => None,
|
||||
// Older snapshots do not carry spend-control state, so preserve the
|
||||
// historical interpretation for compatibility.
|
||||
(false, None) => Some(false),
|
||||
}?;
|
||||
|
||||
Some(match blocked_state {
|
||||
true => UsageBasedWorkspaceBlockKind::CreditsDepleted,
|
||||
false => UsageBasedWorkspaceBlockKind::SpendCapReached,
|
||||
})
|
||||
}
|
||||
|
||||
fn usage_based_workspace_rate_limit_error_guidance(&self) -> Option<(String, Option<String>)> {
|
||||
if let Some(state) = self.usage_based_workspace_rate_limit_state() {
|
||||
return match state {
|
||||
UsageBasedWorkspaceRateLimitState::OwnerCreditsDepleted => Some((
|
||||
"Your workspace is out of credits.".to_string(),
|
||||
Some(format!(
|
||||
"Visit {CODEX_USAGE_SETTINGS_URL} to add workspace credits and continue using Codex."
|
||||
)),
|
||||
)),
|
||||
UsageBasedWorkspaceRateLimitState::OwnerSpendCapReached => Some((
|
||||
"Your workspace has reached its spend cap.".to_string(),
|
||||
Some(format!(
|
||||
"Visit {CODEX_USAGE_SETTINGS_URL} to increase your workspace spend cap and continue using Codex."
|
||||
)),
|
||||
)),
|
||||
UsageBasedWorkspaceRateLimitState::MemberCreditsDepleted => {
|
||||
Some((WORKSPACE_OWNER_NOTIFICATION_PROMPT.to_string(), None))
|
||||
}
|
||||
UsageBasedWorkspaceRateLimitState::MemberSpendCapReached => Some((
|
||||
"Your workspace has reached its spend cap.".to_string(),
|
||||
Some(format!(
|
||||
"Ask an admin to increase your workspace spend cap. Visit {CODEX_USAGE_SETTINGS_URL} for usage settings."
|
||||
)),
|
||||
)),
|
||||
};
|
||||
}
|
||||
|
||||
match self.usage_based_workspace_block_kind()? {
|
||||
UsageBasedWorkspaceBlockKind::CreditsDepleted => Some((
|
||||
"Your workspace is out of credits.".to_string(),
|
||||
Some(format!(
|
||||
"If you're the workspace owner, visit {CODEX_USAGE_SETTINGS_URL} to add credits. Otherwise wait a moment while Codex refreshes your workspace status."
|
||||
)),
|
||||
)),
|
||||
UsageBasedWorkspaceBlockKind::SpendCapReached => Some((
|
||||
"Your workspace has reached its spend cap.".to_string(),
|
||||
Some(format!(
|
||||
"Ask an admin to increase the workspace spend cap, or visit {CODEX_USAGE_SETTINGS_URL} for usage settings."
|
||||
)),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn next_rate_limit_refresh_request_id(&mut self) -> u64 {
|
||||
let request_id = self.next_status_refresh_request_id;
|
||||
self.next_status_refresh_request_id = self.next_status_refresh_request_id.wrapping_add(1);
|
||||
request_id
|
||||
}
|
||||
|
||||
fn send_rate_limit_refresh_request(&self, request_id: u64) {
|
||||
self.app_event_tx.send(AppEvent::RefreshRateLimits {
|
||||
origin: RateLimitRefreshOrigin::StatusCommand { request_id },
|
||||
});
|
||||
}
|
||||
|
||||
fn request_rate_limit_refresh(&mut self) -> u64 {
|
||||
let request_id = self.next_rate_limit_refresh_request_id();
|
||||
self.send_rate_limit_refresh_request(request_id);
|
||||
request_id
|
||||
}
|
||||
|
||||
fn missing_usage_based_workspace_rate_limit_snapshot(&self) -> bool {
|
||||
self.should_prefetch_rate_limits()
|
||||
&& self.plan_type.is_some()
|
||||
&& !self.rate_limit_snapshots_by_limit_id.contains_key("codex")
|
||||
}
|
||||
|
||||
fn should_prompt_workspace_owner_notification(&self) -> bool {
|
||||
if self.notify_workspace_owner_in_flight {
|
||||
return false;
|
||||
}
|
||||
|
||||
if matches!(
|
||||
self.usage_based_workspace_rate_limit_state(),
|
||||
Some(UsageBasedWorkspaceRateLimitState::MemberCreditsDepleted)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let is_workspace_owner = self.current_is_workspace_owner();
|
||||
if !self.plan_type.is_some_and(is_usage_based_workspace_plan)
|
||||
|| is_workspace_owner == Some(true)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
let block_kind = self.usage_based_workspace_block_kind();
|
||||
block_kind != Some(UsageBasedWorkspaceBlockKind::SpendCapReached)
|
||||
}
|
||||
|
||||
fn maybe_show_pending_workspace_owner_notification_prompt(&mut self) {
|
||||
if !self.pending_workspace_owner_notification_prompt {
|
||||
return;
|
||||
}
|
||||
if self.notify_workspace_owner_in_flight {
|
||||
self.pending_workspace_owner_notification_prompt = false;
|
||||
return;
|
||||
}
|
||||
if !self.bottom_pane.no_modal_or_popup_active() {
|
||||
return;
|
||||
}
|
||||
|
||||
match self.usage_based_workspace_rate_limit_state() {
|
||||
Some(UsageBasedWorkspaceRateLimitState::MemberCreditsDepleted) => {
|
||||
self.pending_workspace_owner_notification_prompt = false;
|
||||
self.open_workspace_owner_notification_prompt();
|
||||
}
|
||||
Some(_) => {
|
||||
self.pending_workspace_owner_notification_prompt = false;
|
||||
}
|
||||
None => {
|
||||
if self.usage_based_workspace_block_kind()
|
||||
== Some(UsageBasedWorkspaceBlockKind::CreditsDepleted)
|
||||
&& self.current_is_workspace_owner().is_none()
|
||||
{
|
||||
return;
|
||||
}
|
||||
if !self.missing_usage_based_workspace_rate_limit_snapshot() {
|
||||
self.pending_workspace_owner_notification_prompt = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn open_workspace_owner_notification_prompt(&mut self) {
|
||||
let items = vec![
|
||||
SelectionItem {
|
||||
name: "Yes".to_string(),
|
||||
display_shortcut: Some(key_hint::plain(KeyCode::Char('y'))),
|
||||
actions: vec![Box::new(|tx| tx.send(AppEvent::NotifyWorkspaceOwner))],
|
||||
dismiss_on_select: true,
|
||||
..Default::default()
|
||||
},
|
||||
SelectionItem {
|
||||
name: "No".to_string(),
|
||||
display_shortcut: Some(key_hint::plain(KeyCode::Char('n'))),
|
||||
dismiss_on_select: true,
|
||||
..Default::default()
|
||||
},
|
||||
];
|
||||
|
||||
self.bottom_pane.show_selection_view(SelectionViewParams {
|
||||
title: Some(WORKSPACE_OWNER_NOTIFICATION_TITLE.to_string()),
|
||||
footer_hint: Some(standard_popup_hint_line()),
|
||||
items,
|
||||
initial_selected_idx: Some(1),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn start_notify_workspace_owner(&mut self) {
|
||||
self.notify_workspace_owner_in_flight = true;
|
||||
self.pending_workspace_owner_notification_prompt = false;
|
||||
}
|
||||
|
||||
pub(crate) fn finish_notify_workspace_owner(
|
||||
&mut self,
|
||||
result: Result<AddCreditsNudgeEmailStatus, String>,
|
||||
) {
|
||||
self.notify_workspace_owner_in_flight = false;
|
||||
self.pending_workspace_owner_notification_prompt = false;
|
||||
match result {
|
||||
Ok(AddCreditsNudgeEmailStatus::Sent) => {
|
||||
self.add_info_message("Workspace owner notified.".to_string(), /*hint*/ None);
|
||||
}
|
||||
Ok(AddCreditsNudgeEmailStatus::CooldownActive) => {
|
||||
self.add_info_message(
|
||||
"Workspace owner was already notified recently.".to_string(),
|
||||
/*hint*/ None,
|
||||
);
|
||||
}
|
||||
Err(_) => {
|
||||
self.add_error_message(
|
||||
"Could not notify your workspace owner. Please try again.".to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn update_account_state(
|
||||
&mut self,
|
||||
status_account_display: Option<StatusAccountDisplay>,
|
||||
workspace_role: Option<AppServerWorkspaceRole>,
|
||||
is_workspace_owner: Option<bool>,
|
||||
plan_type: Option<PlanType>,
|
||||
has_chatgpt_account: bool,
|
||||
) {
|
||||
self.status_account_display = status_account_display;
|
||||
self.workspace_role = workspace_role;
|
||||
self.is_workspace_owner = is_workspace_owner;
|
||||
self.plan_type = plan_type;
|
||||
self.has_chatgpt_account = has_chatgpt_account;
|
||||
self.maybe_show_pending_workspace_owner_notification_prompt();
|
||||
self.bottom_pane
|
||||
.set_connectors_enabled(self.connectors_enabled());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user