Panics · P36 Account: handlers in new; gone accounts, workspaces, providers and roles mark none; expiries refuse overflow
This commit is contained in:
1 parent
ad472490e0
commit
e7aec1651e
19 files changed
+476
-518
No files matched your search
@@ -73,23 +73,20 @@ pub fn switchers(window: &mut Window, cx: &mut App) -> impl IntoElement + use<>
|
||||
.gap_6()
|
||||
.child(
|
||||
div().w(px(260.)).flex().flex_col().gap_2().child(
|
||||
WorkspaceSwitcher::new("account-workspaces", workspaces, workspace)
|
||||
.on_select(move |key, _, cx| change(&to_workspace, cx, |places| places.workspace = key.clone()))
|
||||
WorkspaceSwitcher::new("account-workspaces", workspaces, workspace, move |key, _, cx| change(&to_workspace, cx, |places| places.workspace = key.clone()))
|
||||
.on_create(|_, _| log::info!("gallery: create workspace")),
|
||||
)
|
||||
.child(
|
||||
AccountSwitcher::new("account-accounts", accounts, account)
|
||||
.on_select(move |key, _, cx| change(&to_account, cx, |places| places.account = key.clone()))
|
||||
AccountSwitcher::new("account-accounts", accounts, account, move |key, _, cx| change(&to_account, cx, |places| places.account = key.clone()))
|
||||
.on_add(|_, _| log::info!("gallery: add account")),
|
||||
),
|
||||
)
|
||||
.child(probe(
|
||||
"account-user",
|
||||
UserMenu::new("account-user", "Ada Lovelace", "ada@atlas.dev")
|
||||
UserMenu::new("account-user", "Ada Lovelace", "ada@atlas.dev", |_, _| log::info!("gallery: sign out"))
|
||||
.presence(Presence::Online)
|
||||
.item(MenuItem::new("Profile").icon(IconName::User).on_click(|_, _| log::info!("gallery: profile")))
|
||||
.item(MenuItem::new("Settings").icon(IconName::Settings).on_click(|_, _| log::info!("gallery: settings")))
|
||||
.on_sign_out(|_, _| log::info!("gallery: sign out")),
|
||||
.item(MenuItem::new("Settings").icon(IconName::Settings).on_click(|_, _| log::info!("gallery: settings"))),
|
||||
)),
|
||||
)
|
||||
}
|
||||
@@ -133,7 +130,7 @@ pub fn profile(window: &mut Window, cx: &mut App) -> impl IntoElement + use<> {
|
||||
.action(Button::new("account-card-profile", "View profile")),
|
||||
),
|
||||
)
|
||||
.child(div().w(px(400.)).child(ProfileEditor::new("account-editor", now).on_save(move |profile, _, cx| {
|
||||
.child(div().w(px(400.)).child(ProfileEditor::new("account-editor", now, move |profile, _, cx| {
|
||||
let profile = profile.clone();
|
||||
change(&saved, cx, move |now| *now = profile)
|
||||
}))),
|
||||
@@ -215,8 +212,10 @@ pub fn security_page(window: &mut Window, cx: &mut App) -> impl IntoElement + us
|
||||
let now = state.read(cx);
|
||||
let (sessions, keys, secret) = (now.sessions.clone(), now.keys.clone(), now.secret.clone());
|
||||
let [out, others, made, revoked, done] = [(); 5].map(|_| state.clone());
|
||||
let mut manager = ApiKeyManager::new("account-keys", keys)
|
||||
.on_create(move |name, _, cx| {
|
||||
let mut manager = ApiKeyManager::new(
|
||||
"account-keys",
|
||||
keys,
|
||||
move |name, _, cx| {
|
||||
let name = name.clone();
|
||||
change(&made, cx, move |security| {
|
||||
security.made += 1;
|
||||
@@ -233,14 +232,15 @@ pub fn security_page(window: &mut Window, cx: &mut App) -> impl IntoElement + us
|
||||
);
|
||||
security.secret = Some("ely_live_5f1c0a9e2b7d4c8a3e6f7d3e".into());
|
||||
})
|
||||
})
|
||||
.on_revoke(move |key, _, cx| {
|
||||
},
|
||||
move |key, _, cx| {
|
||||
let key = key.clone();
|
||||
change(&revoked, cx, move |security| {
|
||||
security.keys.retain(|each| each.key != key)
|
||||
})
|
||||
})
|
||||
.on_dismiss(move |_, cx| change(&done, cx, |security| security.secret = None));
|
||||
},
|
||||
move |_, cx| change(&done, cx, |security| security.secret = None),
|
||||
);
|
||||
if let Some(secret) = secret {
|
||||
manager = manager.secret(secret);
|
||||
}
|
||||
@@ -256,8 +256,7 @@ pub fn security_page(window: &mut Window, cx: &mut App) -> impl IntoElement + us
|
||||
.items_start()
|
||||
.gap_8()
|
||||
.child(div().w(px(380.)).child(
|
||||
SessionList::new("account-sessions", sessions)
|
||||
.on_sign_out(move |key, _, cx| {
|
||||
SessionList::new("account-sessions", sessions, move |key, _, cx| {
|
||||
let key = key.clone();
|
||||
change(&out, cx, move |security| security.sessions.retain(|each| each.key != key))
|
||||
})
|
||||
|
||||
@@ -68,7 +68,7 @@ pub fn plan(window: &mut Window, cx: &mut App) -> impl IntoElement + use<> {
|
||||
),
|
||||
)
|
||||
.child(div().w(px(360.)).flex().flex_col().gap_3().child(
|
||||
PaymentMethodForm::new("account-card-form").on_submit(move |card, _, cx| {
|
||||
PaymentMethodForm::new("account-card-form", move |card, _, cx| {
|
||||
let saved_as: SharedString = format!("{} ending {}", card.brand.name(), &card.number[card.number.len() - 4..]).into();
|
||||
change(&saved, cx, move |plan| plan.card = Some(saved_as))
|
||||
}),
|
||||
@@ -116,18 +116,16 @@ pub fn history(_: &mut Window, cx: &mut App) -> impl IntoElement + use<> {
|
||||
.flex_col()
|
||||
.gap_4()
|
||||
.child(
|
||||
UpgradePrompt::new("account-nudge", "9 of 10 projects used")
|
||||
UpgradePrompt::new("account-nudge", "9 of 10 projects used", |_, _| log::info!("gallery: upgrade"))
|
||||
.body("Pro has no limit on projects.")
|
||||
.on_upgrade(|_, _| log::info!("gallery: upgrade"))
|
||||
.on_dismiss(|_, _| log::info!("gallery: not now")),
|
||||
)
|
||||
.child(
|
||||
UpgradePrompt::new("account-wall", "Version history is on Pro")
|
||||
UpgradePrompt::new("account-wall", "Version history is on Pro", |_, _| log::info!("gallery: upgrade"))
|
||||
.body("See and restore every version of a document.")
|
||||
.benefit("Every version, kept a year")
|
||||
.benefit("Restore with one press")
|
||||
.benefit("Compare any two")
|
||||
.on_upgrade(|_, _| log::info!("gallery: upgrade"))
|
||||
.on_dismiss(|_, _| log::info!("gallery: not now")),
|
||||
),
|
||||
),
|
||||
@@ -207,27 +205,22 @@ pub fn members(window: &mut Window, cx: &mut App) -> impl IntoElement + use<> {
|
||||
.gap_6()
|
||||
.w(px(640.))
|
||||
.child(
|
||||
TeamMemberTable::new("account-members", members, roles())
|
||||
.on_role(move |key, next, _, cx| {
|
||||
TeamMemberTable::new("account-members", members, roles(), move |key, next, _, cx| {
|
||||
let (key, next) = (key.clone(), next.clone());
|
||||
change(&role, cx, move |team| team.members.iter_mut().filter(|member| member.key == key).for_each(|member| member.role = next.clone()))
|
||||
})
|
||||
.on_remove(move |key, _, cx| {
|
||||
}, move |key, _, cx| {
|
||||
let key = key.clone();
|
||||
change(&removed, cx, move |team| team.members.retain(|member| member.key != key))
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
InvitationList::new("account-invites", invitations, roles())
|
||||
.on_invite(move |email, role, _, cx| {
|
||||
InvitationList::new("account-invites", invitations, roles(), move |email, role, _, cx| {
|
||||
let (email, role) = (email.clone(), role.clone());
|
||||
change(&invited, cx, move |team| {
|
||||
team.sent += 1;
|
||||
team.invitations.insert(0, Invitation { key: format!("new-{}", team.sent).into(), email, role, sent: "Sent just now".into(), expired: false });
|
||||
})
|
||||
})
|
||||
.on_resend(|key, _, _| log::info!("gallery: resend {key}"))
|
||||
.on_revoke(move |key, _, cx| {
|
||||
}, |key, _, _| log::info!("gallery: resend {key}"), move |key, _, cx| {
|
||||
let key = key.clone();
|
||||
change(&revoked, cx, move |team| team.invitations.retain(|each| each.key != key))
|
||||
}),
|
||||
|
||||
@@ -30,19 +30,18 @@ pub fn sign_in(window: &mut Window, cx: &mut App) -> impl IntoElement + use<> {
|
||||
("google", "Google"),
|
||||
("apple", "Apple"),
|
||||
],
|
||||
)
|
||||
.on_pick(move |key, _, cx| change(&picked, cx, |state| state.provider = Some(key.clone())));
|
||||
move |key, _, cx| change(&picked, cx, |state| state.provider = Some(key.clone())),
|
||||
);
|
||||
if let Some(provider) = provider {
|
||||
providers = providers.busy(provider);
|
||||
}
|
||||
let mut form = LoginForm::new("account-login")
|
||||
.on_submit(move |_, _, cx| {
|
||||
change(&tried, cx, |state| {
|
||||
state.error = Some("No account uses that email and password.".into())
|
||||
})
|
||||
let mut form = LoginForm::new("account-login", move |_, _, cx| {
|
||||
change(&tried, cx, |state| {
|
||||
state.error = Some("No account uses that email and password.".into())
|
||||
})
|
||||
.on_forgot(|_, _| log::info!("gallery: forgot password"))
|
||||
.on_sign_up(|_, _| log::info!("gallery: sign up"));
|
||||
})
|
||||
.on_forgot(|_, _| log::info!("gallery: forgot password"))
|
||||
.on_sign_up(|_, _| log::info!("gallery: sign up"));
|
||||
if let Some(error) = error {
|
||||
form = form.error(error);
|
||||
}
|
||||
@@ -71,13 +70,12 @@ pub fn sign_up(window: &mut Window, cx: &mut App) -> impl IntoElement + use<> {
|
||||
let state = keep("account-sign-up", SignUp::default, window, cx);
|
||||
let error = state.read(cx).error.clone();
|
||||
let tried = state.clone();
|
||||
let mut form = SignupForm::new("account-signup")
|
||||
.terms("I agree to the terms of service")
|
||||
.on_submit(move |signup, _, cx| {
|
||||
let taken = format!("An account already uses {}.", signup.email);
|
||||
change(&tried, cx, |state| state.error = Some(taken.into()))
|
||||
})
|
||||
.on_sign_in(|_, _| log::info!("gallery: sign in"));
|
||||
let mut form = SignupForm::new("account-signup", move |signup, _, cx| {
|
||||
let taken = format!("An account already uses {}.", signup.email);
|
||||
change(&tried, cx, |state| state.error = Some(taken.into()))
|
||||
})
|
||||
.terms("I agree to the terms of service")
|
||||
.on_sign_in(|_, _| log::info!("gallery: sign in"));
|
||||
if let Some(error) = error {
|
||||
form = form.error(error);
|
||||
}
|
||||
@@ -115,9 +113,8 @@ pub fn by_email(window: &mut Window, cx: &mut App) -> impl IntoElement + use<> {
|
||||
"account-magic",
|
||||
div().w(px(360.)).child(
|
||||
Card::new().header(CardHeader::new("Sign in by email")).child(
|
||||
MagicLinkForm::new("account-magic")
|
||||
MagicLinkForm::new("account-magic", move |_, _, cx| change(&sent, cx, |state| state.magic = true))
|
||||
.sent(magic)
|
||||
.on_send(move |_, _, cx| change(&sent, cx, |state| state.magic = true))
|
||||
.on_other(move |_, cx| change(&other, cx, |state| state.magic = false)),
|
||||
),
|
||||
),
|
||||
@@ -125,9 +122,8 @@ pub fn by_email(window: &mut Window, cx: &mut App) -> impl IntoElement + use<> {
|
||||
.child(
|
||||
div().w(px(360.)).child(
|
||||
Card::new().header(CardHeader::new("Reset your password")).child(
|
||||
ForgotPassword::new("account-forgot")
|
||||
ForgotPassword::new("account-forgot", move |_, _, cx| change(&asked, cx, |state| state.reset = true))
|
||||
.sent(reset)
|
||||
.on_send(move |_, _, cx| change(&asked, cx, |state| state.reset = true))
|
||||
.on_back(move |_, cx| change(&back, cx, |state| state.reset = false)),
|
||||
),
|
||||
),
|
||||
@@ -161,14 +157,13 @@ pub fn second_factor(window: &mut Window, cx: &mut App) -> impl IntoElement + us
|
||||
Card::new()
|
||||
.header(CardHeader::new("Two-step sign-in"))
|
||||
.child(
|
||||
TwoFactorInput::new("account-factor")
|
||||
.failed(failed)
|
||||
.on_code(move |code, _, cx| {
|
||||
TwoFactorInput::new("account-factor", move |code, _, cx| {
|
||||
change(&checked, cx, |state| match code.as_ref() == CODE {
|
||||
true => state.passed = true,
|
||||
false => state.failed += 1,
|
||||
})
|
||||
})
|
||||
.failed(failed)
|
||||
.on_recovery(|_, _| log::info!("gallery: recovery code")),
|
||||
)
|
||||
.children(passed.then(|| InlineMessage::new(Severity::Success, "Signed in."))),
|
||||
|
||||
Reference in new issue
Block a user