element-web/src/toasts/AnalyticsToast.tsx
Suguru Hirahara 731776d189
Improve link buttons and inline link buttons styling (#8238)
* Set padding: 0 to both "link" and "link_inline"

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Remove redundant settings - _SpotlightDialog.scss

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Remove redundant settings - JoinRuleSettings

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Remove redundant settings - _ViewSourceEvent.scss

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Remove redundant settings - _RoomDirectory.scss

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Remove redundant settings - _InviteDialog.scss

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Remove redundant settings - ServerOfflineDialog

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Remove redundant settings - UpdateCheckButton

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Remove redundant settings - NonUrgentEchoFailureToast

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Remove redundant settings - CallView

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Remove unused styles - _RoomSettingsDialogBridges.scss

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Replace "link" with "link_inline" for inline links

- src/components/structures/UserMenu.tsx
- src/components/views/dialogs/BetaFeedbackDialog.tsx
- src/components/views/dialogs/FeedbackDialog.tsx
- src/components/views/rooms/NewRoomIntro.tsx
- src/components/views/settings/tabs/room/NotificationSettingsTab.tsx
- src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx
- src/components/views/spaces/SpaceCreateMenu.tsx

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Replace "link_inline" with "link" for links not inline

- src/async-components/views/dialogs/security/CreateKeyBackupDialog.tsx
- src/async-components/views/dialogs/security/CreateSecretStorageDialog.tsx
- src/components/structures/auth/ForgotPassword.tsx
- src/components/structures/auth/Registration.tsx
- src/components/views/auth/InteractiveAuthEntryComponents.tsx
- src/components/views/dialogs/security/AccessSecretStorageDialog.tsx
- src/components/views/dialogs/security/RestoreKeyBackupDialog.tsx
- src/components/views/messages/TileErrorBoundary.tsx
- src/components/views/messages/ViewSourceEvent.tsx

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Remove a redundant declaration - _SetupEncryptionBody.scss

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Remove a redundant declaration - _ReplyChain.scss

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Remove a redundant declaration - _EventTile.scss

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Remove an obsolete style block - _RoomPreviewCard.scss

The block was transferred from _SpaceRoomView.scss with ec24dc661edb6979ba901936067e5bc731dafa59

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Remove a redundant declaration - _SecurityUserSettingsTab.scss

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Remove element='span' - NewRoomIntro.tsx

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Remove redundant declarations - _ServerPicker.scss

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>

* Replace 'link' with 'link_inline' - AnalyticsToast.tsx

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>
2022-06-29 22:37:34 +00:00

141 lines
5 KiB
TypeScript

/*
Copyright 2020 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import React from "react";
import { Optional } from "matrix-events-sdk";
import { _t } from "../languageHandler";
import SdkConfig from "../SdkConfig";
import dis from "../dispatcher/dispatcher";
import AccessibleButton from "../components/views/elements/AccessibleButton";
import GenericToast from "../components/views/toasts/GenericToast";
import ToastStore from "../stores/ToastStore";
import {
ButtonClicked,
showDialog as showAnalyticsLearnMoreDialog,
} from "../components/views/dialogs/AnalyticsLearnMoreDialog";
import { Action } from "../dispatcher/actions";
import { SnakedObject } from "../utils/SnakedObject";
import { IConfigOptions } from "../IConfigOptions";
import SettingsStore from "../settings/SettingsStore";
const onAccept = () => {
dis.dispatch({
action: Action.PseudonymousAnalyticsAccept,
});
};
const onReject = () => {
dis.dispatch({
action: Action.PseudonymousAnalyticsReject,
});
};
const onLearnMoreNoOptIn = () => {
showAnalyticsLearnMoreDialog({
onFinished: (buttonClicked?: ButtonClicked) => {
if (buttonClicked === ButtonClicked.Primary) {
// user clicked "Enable"
onAccept();
}
// otherwise, the user either clicked "Cancel", or closed the dialog without making a choice,
// leave the toast open
},
primaryButton: _t("Enable"),
});
};
const onLearnMorePreviouslyOptedIn = () => {
showAnalyticsLearnMoreDialog({
onFinished: (buttonClicked?: ButtonClicked) => {
if (buttonClicked === ButtonClicked.Primary) {
// user clicked "That's fine"
onAccept();
} else if (buttonClicked === ButtonClicked.Cancel) {
// user clicked "Stop"
onReject();
}
// otherwise, the user closed the dialog without making a choice, leave the toast open
},
primaryButton: _t("That's fine"),
cancelButton: _t("Stop"),
});
};
const TOAST_KEY = "analytics";
export function getPolicyUrl(): Optional<string> {
const policyUrl = SdkConfig.get("privacy_policy_url");
if (policyUrl) return policyUrl;
// Try get from legacy config location
const piwikConfig = SdkConfig.get("piwik");
let piwik: Optional<SnakedObject<Extract<IConfigOptions["piwik"], object>>>;
if (typeof piwikConfig === 'object') {
piwik = new SnakedObject(piwikConfig);
}
return piwik?.get("policy_url");
}
export const showToast = (): void => {
const legacyAnalyticsOptIn = SettingsStore.getValue("analyticsOptIn", null, true);
let props: Omit<React.ComponentProps<typeof GenericToast>, "toastKey">;
if (legacyAnalyticsOptIn) {
// The user previously opted into our old analytics system - let them know things have changed and ask
// them to opt in again.
props = {
description: _t(
"You previously consented to share anonymous usage data with us. We're updating how that works."),
acceptLabel: _t("That's fine"),
onAccept,
rejectLabel: _t("Learn more"),
onReject: onLearnMorePreviouslyOptedIn,
};
} else if (legacyAnalyticsOptIn === null || legacyAnalyticsOptIn === undefined) {
// The user had no analytics setting previously set, so we just need to prompt to opt-in, rather than
// explaining any change.
const learnMoreLink = (sub: string) => (
<AccessibleButton kind="link_inline" onClick={onLearnMoreNoOptIn}>{ sub }</AccessibleButton>
);
props = {
description: _t(
"Share anonymous data to help us identify issues. Nothing personal. No third parties. " +
"<LearnMoreLink>Learn More</LearnMoreLink>", {}, { "LearnMoreLink": learnMoreLink }),
acceptLabel: _t("Yes"),
onAccept,
rejectLabel: _t("No"),
onReject,
};
} else { // false
// The user previously opted out of analytics, don't ask again
return;
}
const analyticsOwner = SdkConfig.get("analytics_owner") ?? SdkConfig.get().brand;
ToastStore.sharedInstance().addOrReplaceToast({
key: TOAST_KEY,
title: _t("Help improve %(analyticsOwner)s", { analyticsOwner }),
props,
component: GenericToast,
className: "mx_AnalyticsToast",
priority: 10,
});
};
export const hideToast = () => {
ToastStore.sharedInstance().dismissToast(TOAST_KEY);
};