signal-desktop/ts/components/AddGroupMemberErrorDialog.tsx

61 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-03-04 19:48:44 +00:00
// Copyright 2021-2022 Signal Messenger, LLC
2021-03-11 21:29:31 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import type { FunctionComponent, ReactNode } from 'react';
import React from 'react';
2021-03-11 21:29:31 +00:00
import type { LocalizerType } from '../types/Util';
2021-03-11 21:29:31 +00:00
import { Alert } from './Alert';
import { missingCaseError } from '../util/missingCaseError';
export enum AddGroupMemberErrorDialogMode {
MaximumGroupSize,
RecommendedMaximumGroupSize,
}
type PropsDataType =
| {
mode: AddGroupMemberErrorDialogMode.MaximumGroupSize;
maximumNumberOfContacts: number;
}
| {
mode: AddGroupMemberErrorDialogMode.RecommendedMaximumGroupSize;
recommendedMaximumNumberOfContacts: number;
};
type PropsType = {
i18n: LocalizerType;
onClose: () => void;
} & PropsDataType;
2022-03-22 20:45:34 +00:00
export const AddGroupMemberErrorDialog: FunctionComponent<
PropsType
> = props => {
const { i18n, onClose } = props;
let title: string;
let body: ReactNode;
switch (props.mode) {
case AddGroupMemberErrorDialogMode.MaximumGroupSize: {
const { maximumNumberOfContacts } = props;
title = i18n('chooseGroupMembers__maximum-group-size__title');
body = i18n('chooseGroupMembers__maximum-group-size__body', [
maximumNumberOfContacts.toString(),
]);
break;
2021-03-11 21:29:31 +00:00
}
2022-03-22 20:45:34 +00:00
case AddGroupMemberErrorDialogMode.RecommendedMaximumGroupSize: {
const { recommendedMaximumNumberOfContacts } = props;
title = i18n('chooseGroupMembers__maximum-recommended-group-size__title');
body = i18n('chooseGroupMembers__maximum-recommended-group-size__body', [
recommendedMaximumNumberOfContacts.toString(),
]);
break;
}
default:
throw missingCaseError(props);
}
2021-03-11 21:29:31 +00:00
2022-03-22 20:45:34 +00:00
return <Alert body={body} i18n={i18n} onClose={onClose} title={title} />;
};