signal-desktop/ts/components/installScreen/InstallScreenQrCodeNotScannedStep.stories.tsx

206 lines
5.2 KiB
TypeScript
Raw Normal View History

2021-12-16 15:02:22 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React, { useEffect, useState } from 'react';
2023-03-20 20:42:00 +00:00
import { action } from '@storybook/addon-actions';
import type { Meta, StoryFn } from '@storybook/react';
2021-12-16 15:02:22 +00:00
import { setupI18n } from '../../util/setupI18n';
2023-03-20 20:42:00 +00:00
import { DialogType } from '../../types/Dialogs';
2024-09-04 02:56:13 +00:00
import { InstallScreenQRCodeError } from '../../types/InstallScreen';
2021-12-16 15:02:22 +00:00
import enMessages from '../../../_locales/en/messages.json';
import type { Loadable } from '../../util/loadable';
import { LoadingState } from '../../util/loadable';
import type { PropsType } from './InstallScreenQrCodeNotScannedStep';
2024-09-04 02:56:13 +00:00
import { InstallScreenQrCodeNotScannedStep } from './InstallScreenQrCodeNotScannedStep';
2021-12-16 15:02:22 +00:00
const i18n = setupI18n('en', enMessages);
2023-03-20 20:42:00 +00:00
const LOADED_URL = {
loadingState: LoadingState.Loaded as const,
value:
'sgnl://linkdevice?uuid=b33f6338-aaf1-4853-9aff-6652369f6b52&pub_key=BTpRKRtFeJGga1M3Na4PzZevMvVIWmTWQIpn0BJI3x10',
};
const DEFAULT_UPDATES = {
dialogType: DialogType.None,
didSnooze: false,
isCheckingForUpdates: false,
2023-03-20 20:42:00 +00:00
showEventsCount: 0,
downloadSize: 67 * 1024 * 1024,
downloadedSize: 15 * 1024 * 1024,
version: 'v7.7.7',
};
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/InstallScreen/InstallScreenQrCodeNotScannedStep',
2023-03-20 20:42:00 +00:00
argTypes: {},
} satisfies Meta<PropsType>;
2021-12-16 15:02:22 +00:00
2024-07-01 21:51:49 +00:00
function Simulation({
finalResult,
}: {
2024-09-04 02:56:13 +00:00
finalResult: Loadable<string, InstallScreenQRCodeError>;
2024-07-01 21:51:49 +00:00
}) {
const [provisioningUrl, setProvisioningUrl] = useState<
2024-09-04 02:56:13 +00:00
Loadable<string, InstallScreenQRCodeError>
2024-07-01 21:51:49 +00:00
>({
2021-12-16 15:02:22 +00:00
loadingState: LoadingState.Loading,
});
useEffect(() => {
const timeout = setTimeout(() => {
setProvisioningUrl(finalResult);
}, 2000);
return () => {
clearTimeout(timeout);
};
}, [finalResult]);
return (
<InstallScreenQrCodeNotScannedStep
i18n={i18n}
2024-09-04 18:12:45 +00:00
isStaging={false}
2021-12-16 15:02:22 +00:00
provisioningUrl={provisioningUrl}
2023-03-20 20:42:00 +00:00
updates={DEFAULT_UPDATES}
OS="macOS"
startUpdate={action('startUpdate')}
forceUpdate={action('forceUpdate')}
2023-03-20 20:42:00 +00:00
currentVersion="v6.0.0"
retryGetQrCode={action('retryGetQrCode')}
2021-12-16 15:02:22 +00:00
/>
);
2022-11-18 00:45:19 +00:00
}
2021-12-16 15:02:22 +00:00
2022-11-18 00:45:19 +00:00
export function QrCodeLoading(): JSX.Element {
return (
<InstallScreenQrCodeNotScannedStep
i18n={i18n}
2024-09-04 18:12:45 +00:00
isStaging={false}
2022-11-18 00:45:19 +00:00
provisioningUrl={{
loadingState: LoadingState.Loading,
}}
2023-03-20 20:42:00 +00:00
updates={DEFAULT_UPDATES}
OS="macOS"
startUpdate={action('startUpdate')}
forceUpdate={action('forceUpdate')}
2023-03-20 20:42:00 +00:00
currentVersion="v6.0.0"
retryGetQrCode={action('retryGetQrCode')}
2022-11-18 00:45:19 +00:00
/>
);
}
2021-12-16 15:02:22 +00:00
2022-11-18 00:45:19 +00:00
export function QrCodeFailedToLoad(): JSX.Element {
return (
<InstallScreenQrCodeNotScannedStep
i18n={i18n}
2024-09-04 18:12:45 +00:00
isStaging={false}
2022-11-18 00:45:19 +00:00
provisioningUrl={{
loadingState: LoadingState.LoadFailed,
2024-09-04 02:56:13 +00:00
error: InstallScreenQRCodeError.Unknown,
2022-11-18 00:45:19 +00:00
}}
2023-03-20 20:42:00 +00:00
updates={DEFAULT_UPDATES}
OS="macOS"
startUpdate={action('startUpdate')}
forceUpdate={action('forceUpdate')}
2023-03-20 20:42:00 +00:00
currentVersion="v6.0.0"
retryGetQrCode={action('retryGetQrCode')}
2022-11-18 00:45:19 +00:00
/>
);
}
2022-06-07 00:48:02 +00:00
2022-11-18 00:45:19 +00:00
export function QrCodeLoaded(): JSX.Element {
return (
<InstallScreenQrCodeNotScannedStep
i18n={i18n}
2024-09-04 18:12:45 +00:00
isStaging={false}
2023-03-20 20:42:00 +00:00
provisioningUrl={LOADED_URL}
updates={DEFAULT_UPDATES}
OS="macOS"
startUpdate={action('startUpdate')}
forceUpdate={action('forceUpdate')}
2023-03-20 20:42:00 +00:00
currentVersion="v6.0.0"
retryGetQrCode={action('retryGetQrCode')}
2022-11-18 00:45:19 +00:00
/>
);
}
2022-06-07 00:48:02 +00:00
2022-11-18 00:45:19 +00:00
export function SimulatedLoading(): JSX.Element {
2023-03-20 20:42:00 +00:00
return <Simulation finalResult={LOADED_URL} />;
2022-11-18 00:45:19 +00:00
}
2021-12-16 15:02:22 +00:00
2024-07-01 21:51:49 +00:00
export function SimulatedUnknownError(): JSX.Element {
2022-11-18 00:45:19 +00:00
return (
<Simulation
finalResult={{
loadingState: LoadingState.LoadFailed,
2024-09-04 02:56:13 +00:00
error: InstallScreenQRCodeError.Unknown,
2024-07-01 21:51:49 +00:00
}}
/>
);
}
export function SimulatedNetworkIssue(): JSX.Element {
return (
<Simulation
finalResult={{
loadingState: LoadingState.LoadFailed,
2024-09-04 02:56:13 +00:00
error: InstallScreenQRCodeError.NetworkIssue,
2024-07-01 21:51:49 +00:00
}}
/>
);
}
export function SimulatedTimeout(): JSX.Element {
return (
<Simulation
finalResult={{
loadingState: LoadingState.LoadFailed,
2024-09-04 02:56:13 +00:00
error: InstallScreenQRCodeError.Timeout,
2022-11-18 00:45:19 +00:00
}}
/>
);
}
2022-06-07 00:48:02 +00:00
export const WithUpdateKnobs: StoryFn<PropsType & { dialogType: DialogType }> =
// eslint-disable-next-line react/function-component-definition
function WithUpdateKnobs({
dialogType,
currentVersion,
}: {
dialogType: DialogType;
currentVersion: string;
}): JSX.Element {
return (
<InstallScreenQrCodeNotScannedStep
i18n={i18n}
2024-09-04 18:12:45 +00:00
isStaging={false}
provisioningUrl={LOADED_URL}
hasExpired
updates={{
...DEFAULT_UPDATES,
dialogType,
}}
OS="macOS"
startUpdate={action('startUpdate')}
forceUpdate={action('forceUpdate')}
currentVersion={currentVersion}
retryGetQrCode={action('retryGetQrCode')}
/>
);
};
WithUpdateKnobs.argTypes = {
dialogType: {
control: { type: 'select' },
options: Object.values(DialogType),
},
currentVersion: {
control: { type: 'select' },
options: ['v6.0.0', 'v6.1.0-beta.1'],
2023-03-20 20:42:00 +00:00
},
};
WithUpdateKnobs.args = {
dialogType: DialogType.AutoUpdate,
currentVersion: 'v6.0.0',
};