Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/account/account-button.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Popconfirm, Popover } from "antd";6import React from "react";7import { FormattedMessage, useIntl } from "react-intl";89import { AccountActions } from "@cocalc/frontend/account";10import { labels } from "@cocalc/frontend/i18n";11import { CancelText } from "@cocalc/frontend/i18n/components";1213interface Props {14icon: React.ReactNode; // When clicked, show popover15links: React.ReactNode; // Should change view to correct account settings tab when clicked16label_class: string; // class name for AccountTabDropdown label17show_label: boolean; // This tells button to show18is_active: boolean; // if true set button background to ACTIVE_BG_COLOR19user_label: string;20}2122interface AccountTabProps {23icon;24links;25label_class;26show_label;27is_active;28user_label;29}3031export const AccountTabDropdown: React.FC<Props> = (props: AccountTabProps) => {32const { icon, links, label_class, show_label, is_active, user_label } = props;33const intl = useIntl();3435const label = intl.formatMessage(labels.account);3637// If icon is a string then use the Icon component38// Else (it is a node already) just render icon39return (40<Popover41placement="bottom"42title={"Signed in as " + user_label}43trigger="click"44content={links}45>46<div47style={{48display: "flex",49flex: "0 0 auto",50float: "left",51position: "relative",52height: "30px",53padding: "8px",54whiteSpace: "nowrap",55...(is_active && { backgroundColor: "white" }),56}}57>58{icon}59<span style={{ marginLeft: 5 }} className={label_class}>60{show_label ? label : undefined}61</span>62</div>63</Popover>64);65};6667interface LinksProps {68account_actions: AccountActions;69page_actions: any;70}7172export const DefaultAccountDropDownLinks: React.FC<LinksProps> = ({73account_actions, // Type AccountActions74page_actions, // PageActions (untyped for now)75}) => {76return (77<>78<div className="cocalc-account-button-dropdown-links">79<li>80<a81style={{82width: "100%",83padding: "4px 8px 4px 16px",84display: "inline-block",85}}86className={"cocalc-account-button"}87onClick={(event) => {88event.preventDefault();89page_actions.set_active_tab("account"); // Set to account page90account_actions.set_active_tab("account"); /// Set to the Subs and course packs tab91}}92href=""93>94Preferences95</a>96</li>97<li>98<a99style={{100width: "100%",101padding: "4px 8px 4px 16px",102display: "inline-block",103}}104className={"cocalc-account-button"}105onClick={(event) => {106event.preventDefault();107page_actions.set_active_tab("account"); // Set to account page108account_actions.set_active_tab("billing"); /// Set to the Preferences tab109}}110href=""111>112Billing113</a>114</li>115<li>116<a117style={{118width: "100%",119padding: "4px 8px 4px 16px",120display: "inline-block",121}}122className={"cocalc-account-button"}123onClick={(event) => {124event.preventDefault();125page_actions.set_active_tab("account"); // Set to account page126account_actions.set_active_tab("upgrades"); /// Set to the Preferences tab127}}128href=""129>130Upgrades131</a>132</li>133<li>134<a135style={{136width: "100%",137padding: "4px 8px 4px 16px",138display: "inline-block",139}}140className={"cocalc-account-button"}141onClick={(event) => {142event.preventDefault();143page_actions.set_active_tab("account"); // Set to account page144account_actions.set_active_tab("support"); /// Set to the Preferences tab145}}146href=""147>148Support149</a>150</li>151<li>152<Popconfirm153title={154<FormattedMessage155id="account.account-button.confirm.title"156defaultMessage={"Sign out of your account?"}157/>158}159onConfirm={() => account_actions.sign_out(false, false)}160okText={161<FormattedMessage162id="account.account-button.confirm.ok"163defaultMessage={"Yes, sign out"}164/>165}166cancelText={<CancelText />}167>168<a169style={{170width: "100%",171padding: "4px 8px 4px 16px",172display: "inline-block",173}}174className={"cocalc-account-button"}175href=""176>177Sign out...178</a>179</Popconfirm>180</li>181</div>182</>183);184};185186187