zed ai: Show ToS form in Configuration View (#16736)

Related #16618

Release Notes:

- N/A
This commit is contained in:
Thorsten Ball 2024-08-23 11:17:21 +02:00 committed by GitHub
parent 119e337344
commit 7647644602
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -31,7 +31,7 @@ use std::{
sync::{Arc, LazyLock}, sync::{Arc, LazyLock},
}; };
use strum::IntoEnumIterator; use strum::IntoEnumIterator;
use ui::prelude::*; use ui::{prelude::*, TintColor};
use crate::{LanguageModelAvailability, LanguageModelProvider}; use crate::{LanguageModelAvailability, LanguageModelProvider};
@ -793,6 +793,46 @@ impl ConfigurationView {
}); });
cx.notify(); cx.notify();
} }
fn render_accept_terms(&mut self, cx: &mut ViewContext<Self>) -> Option<AnyElement> {
if self.state.read(cx).has_accepted_terms_of_service(cx) {
return None;
}
let accept_terms_disabled = self.state.read(cx).accept_terms.is_some();
let terms_button = Button::new("terms_of_service", "Terms of Service")
.style(ButtonStyle::Subtle)
.icon(IconName::ExternalLink)
.icon_color(Color::Muted)
.on_click(move |_, cx| cx.open_url("https://zed.dev/terms-of-service"));
let text =
"In order to use Zed AI, please read and accept our terms and conditions to continue:";
let form = v_flex()
.gap_2()
.child(Label::new("Terms and Conditions"))
.child(Label::new(text))
.child(h_flex().justify_center().child(terms_button))
.child(
h_flex().justify_center().child(
Button::new("accept_terms", "I've read and accept the terms of service")
.style(ButtonStyle::Tinted(TintColor::Accent))
.disabled(accept_terms_disabled)
.on_click({
let state = self.state.downgrade();
move |_, cx| {
state
.update(cx, |state, cx| state.accept_terms_of_service(cx))
.ok();
}
}),
),
);
Some(form.into_any())
}
} }
impl Render for ConfigurationView { impl Render for ConfigurationView {
@ -802,33 +842,20 @@ impl Render for ConfigurationView {
let is_connected = !self.state.read(cx).is_signed_out(); let is_connected = !self.state.read(cx).is_signed_out();
let plan = self.state.read(cx).user_store.read(cx).current_plan(); let plan = self.state.read(cx).user_store.read(cx).current_plan();
let must_accept_terms = !self.state.read(cx).has_accepted_terms_of_service(cx); let has_accepted_terms = self.state.read(cx).has_accepted_terms_of_service(cx);
let is_pro = plan == Some(proto::Plan::ZedPro); let is_pro = plan == Some(proto::Plan::ZedPro);
let subscription_text = Label::new(if is_pro {
if is_connected {
v_flex()
.gap_3()
.max_w_4_5()
.when(must_accept_terms, |this| {
this.child(Label::new(
"You must accept the terms of service to use this provider.",
))
})
.child(Label::new(
if is_pro {
"You have full access to Zed's hosted models from Anthropic, OpenAI, Google with faster speeds and higher limits through Zed Pro." "You have full access to Zed's hosted models from Anthropic, OpenAI, Google with faster speeds and higher limits through Zed Pro."
} else { } else {
"You have basic access to models from Anthropic through the Zed AI Free plan." "You have basic access to models from Anthropic through the Zed AI Free plan."
})) });
.children(if is_pro { let manage_subscription_button = if is_pro {
Some( Some(
h_flex().child( h_flex().child(
Button::new("manage_settings", "Manage Subscription") Button::new("manage_settings", "Manage Subscription")
.style(ButtonStyle::Filled) .style(ButtonStyle::Tinted(TintColor::Accent))
.on_click( .on_click(cx.listener(|_, _, cx| cx.open_url(ACCOUNT_SETTINGS_URL))),
cx.listener(|_, _, cx| cx.open_url(ACCOUNT_SETTINGS_URL)),
),
), ),
) )
} else if cx.has_flag::<ZedPro>() { } else if cx.has_flag::<ZedPro>() {
@ -844,13 +871,21 @@ impl Render for ConfigurationView {
Button::new("upgrade", "Upgrade") Button::new("upgrade", "Upgrade")
.style(ButtonStyle::Subtle) .style(ButtonStyle::Subtle)
.color(Color::Accent) .color(Color::Accent)
.on_click( .on_click(cx.listener(|_, _, cx| cx.open_url(ACCOUNT_SETTINGS_URL))),
cx.listener(|_, _, cx| cx.open_url(ACCOUNT_SETTINGS_URL)),
),
), ),
) )
} else { } else {
None None
};
if is_connected {
v_flex()
.gap_3()
.max_w_4_5()
.children(self.render_accept_terms(cx))
.when(has_accepted_terms, |this| {
this.child(subscription_text)
.children(manage_subscription_button)
}) })
} else { } else {
v_flex() v_flex()