Path: blob/master/src/packages/frontend/account/account-preferences-communication.tsx
2209 views
/*1* This file is part of CoCalc: Copyright © 2025 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Button } from "antd";6import { FormattedMessage, useIntl } from "react-intl";78import { Panel, Switch } from "@cocalc/frontend/antd-bootstrap";9import { redux, useTypedRedux } from "@cocalc/frontend/app-framework";10import { Icon, IconName } from "@cocalc/frontend/components";11import { labels } from "@cocalc/frontend/i18n";12import { webapp_client } from "@cocalc/frontend/webapp-client";1314export const COMMUNICATION_ICON_NAME: IconName = "mail";1516export function AccountPreferencesCommunication(): React.JSX.Element {17const intl = useIntl();18const other_settings = useTypedRedux("account", "other_settings");19const stripe_customer = useTypedRedux("account", "stripe_customer");20const email_address_verified = useTypedRedux(21"account",22"email_address_verified",23);24const email_address = useTypedRedux("account", "email_address");25const isVerified = !!email_address_verified?.get(email_address ?? "");26const is_stripe_customer = !!stripe_customer?.getIn([27"subscriptions",28"total_count",29]);3031function on_change(name: string, value: any): void {32redux.getActions("account").set_other_settings(name, value);33}3435function toggle_global_banner(val: boolean): void {36if (val) {37// this must be "null", not "undefined" – otherwise the data isn't stored in the DB.38on_change("show_global_info2", null);39} else {40on_change("show_global_info2", webapp_client.server_time());41}42}4344function render_global_banner() {45return (46<Switch47checked={!other_settings.get("show_global_info2")}48onChange={(e) => toggle_global_banner(e.target.checked)}49>50<FormattedMessage51id="account.other-settings.global_banner"52defaultMessage={`<strong>Show Announcement Banner</strong>: only shows up if there is a53message`}54/>55</Switch>56);57}5859function render_no_free_warnings() {60const extra = is_stripe_customer ? (61<span>(thanks for being a customer)</span>62) : (63<span>(only available to customers)</span>64);6566return (67<Switch68disabled={!is_stripe_customer}69checked={!!other_settings.get("no_free_warnings")}70onChange={(e) => on_change("no_free_warnings", e.target.checked)}71>72<strong>Hide free warnings</strong>: do{" "}73<strong>74<i>not</i>75</strong>{" "}76show a warning banner when using a free trial project {extra}77</Switch>78);79}8081function render_no_email_new_messages() {82return (83<>84<Switch85checked={other_settings.get("no_email_new_messages")}86onChange={(e) => {87on_change("no_email_new_messages", e.target.checked);88}}89>90Do NOT send email when you get new{" "}91<Button92onClick={(e) => {93e.stopPropagation();94redux.getActions("page").set_active_tab("notifications");95redux96.getActions("mentions")97.set_filter("messages-inbox" as "messages-inbox");98}}99type="link"100size="small"101>102Internal Messages103</Button>104</Switch>105{!isVerified && !other_settings.get("no_email_new_messages") && (106<>107(NOTE: You must also verify your email address above to get emails108about new messages.)109</>110)}111</>112);113}114115return (116<Panel117size="small"118header={119<>120<Icon name={COMMUNICATION_ICON_NAME} />{" "}121{intl.formatMessage(labels.communication)}122</>123}124>125{render_global_banner()}126{render_no_free_warnings()}127{render_no_email_new_messages()}128</Panel>129);130}131132133