2020-05-23 00:04:21 +03:00
|
|
|
/*
|
|
|
|
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 { _t } from "../languageHandler";
|
2020-07-10 21:07:11 +03:00
|
|
|
import SdkConfig from "../SdkConfig";
|
2020-05-23 00:04:21 +03:00
|
|
|
import dis from "../dispatcher/dispatcher";
|
|
|
|
import Analytics from "../Analytics";
|
|
|
|
import AccessibleButton from "../components/views/elements/AccessibleButton";
|
|
|
|
import GenericToast from "../components/views/toasts/GenericToast";
|
|
|
|
import ToastStore from "../stores/ToastStore";
|
|
|
|
|
|
|
|
const onAccept = () => {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'accept_cookies',
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const onReject = () => {
|
|
|
|
dis.dispatch({
|
|
|
|
action: "reject_cookies",
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const onUsageDataClicked = () => {
|
|
|
|
Analytics.showDetailsModal();
|
|
|
|
};
|
|
|
|
|
|
|
|
const TOAST_KEY = "analytics";
|
|
|
|
|
|
|
|
export const showToast = (policyUrl?: string) => {
|
2020-07-10 21:07:11 +03:00
|
|
|
const brand = SdkConfig.get().brand;
|
2020-05-23 00:04:21 +03:00
|
|
|
ToastStore.sharedInstance().addOrReplaceToast({
|
|
|
|
key: TOAST_KEY,
|
2020-07-10 21:07:11 +03:00
|
|
|
title: _t("Help us improve %(brand)s", { brand }),
|
2020-05-23 00:04:21 +03:00
|
|
|
props: {
|
|
|
|
description: _t(
|
2020-07-10 21:07:11 +03:00
|
|
|
"Send <UsageDataLink>anonymous usage data</UsageDataLink> which helps us improve %(brand)s. " +
|
2020-05-23 00:04:21 +03:00
|
|
|
"This will use a <PolicyLink>cookie</PolicyLink>.",
|
2020-07-10 21:07:11 +03:00
|
|
|
{
|
|
|
|
brand,
|
|
|
|
},
|
2020-05-23 00:04:21 +03:00
|
|
|
{
|
|
|
|
"UsageDataLink": (sub) => (
|
|
|
|
<AccessibleButton kind="link" onClick={onUsageDataClicked}>{ sub }</AccessibleButton>
|
|
|
|
),
|
|
|
|
// XXX: We need to link to the page that explains our cookies
|
|
|
|
"PolicyLink": (sub) => policyUrl ? (
|
|
|
|
<a target="_blank" href={policyUrl}>{ sub }</a>
|
|
|
|
) : sub,
|
|
|
|
},
|
|
|
|
),
|
2020-11-09 17:21:45 +03:00
|
|
|
acceptLabel: _t("Yes"),
|
2020-05-23 00:04:21 +03:00
|
|
|
onAccept,
|
|
|
|
rejectLabel: _t("No"),
|
|
|
|
onReject,
|
|
|
|
},
|
|
|
|
component: GenericToast,
|
2020-11-09 17:21:45 +03:00
|
|
|
className: "mx_AnalyticsToast",
|
2020-05-23 00:04:21 +03:00
|
|
|
priority: 10,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const hideToast = () => {
|
|
|
|
ToastStore.sharedInstance().dismissToast(TOAST_KEY);
|
|
|
|
};
|