2021-05-28 12:11:19 -07:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 14:15:33 -05:00
|
|
|
import type { ReactElement } from 'react';
|
|
|
|
import React, { useCallback, useState } from 'react';
|
2021-05-28 12:11:19 -07:00
|
|
|
|
2021-08-26 16:51:55 -04:00
|
|
|
import { Button, ButtonSize, ButtonVariant } from '../Button';
|
2021-09-07 14:55:03 -05:00
|
|
|
import { SystemMessage } from './SystemMessage';
|
2021-10-26 14:15:33 -05:00
|
|
|
import type { ConversationType } from '../../state/ducks/conversations';
|
|
|
|
import type { LocalizerType } from '../../types/Util';
|
2024-05-15 14:48:02 -07:00
|
|
|
import { I18n } from '../I18n';
|
2021-05-28 12:11:19 -07:00
|
|
|
|
|
|
|
import { DeliveryIssueDialog } from './DeliveryIssueDialog';
|
2023-04-20 10:03:43 -07:00
|
|
|
import { UserText } from '../UserText';
|
2021-05-28 12:11:19 -07:00
|
|
|
|
|
|
|
export type PropsDataType = {
|
|
|
|
sender?: ConversationType;
|
2021-07-27 13:30:41 -07:00
|
|
|
inGroup: boolean;
|
2021-05-28 12:11:19 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
type PropsHousekeepingType = {
|
|
|
|
i18n: LocalizerType;
|
|
|
|
};
|
|
|
|
|
2022-12-20 19:25:10 -08:00
|
|
|
export type PropsType = PropsDataType & PropsHousekeepingType;
|
2021-05-28 12:11:19 -07:00
|
|
|
|
|
|
|
export function DeliveryIssueNotification(
|
|
|
|
props: PropsType
|
|
|
|
): ReactElement | null {
|
2022-12-20 19:25:10 -08:00
|
|
|
const { i18n, inGroup, sender } = props;
|
2021-05-28 12:11:19 -07:00
|
|
|
const [isDialogOpen, setIsDialogOpen] = useState<boolean>(false);
|
|
|
|
|
|
|
|
const openDialog = useCallback(() => {
|
|
|
|
setIsDialogOpen(true);
|
|
|
|
}, [setIsDialogOpen]);
|
|
|
|
const closeDialog = useCallback(() => {
|
|
|
|
setIsDialogOpen(false);
|
|
|
|
}, [setIsDialogOpen]);
|
|
|
|
|
|
|
|
if (!sender) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-09-07 14:55:03 -05:00
|
|
|
<>
|
|
|
|
<SystemMessage
|
|
|
|
contents={
|
2024-05-15 14:48:02 -07:00
|
|
|
<I18n
|
2023-03-29 17:03:25 -07:00
|
|
|
id="icu:DeliveryIssue--notification"
|
2021-09-02 12:34:00 -05:00
|
|
|
components={{
|
2023-04-20 10:03:43 -07:00
|
|
|
sender: <UserText text={sender.firstName || sender.title} />,
|
2021-09-02 12:34:00 -05:00
|
|
|
}}
|
|
|
|
i18n={i18n}
|
|
|
|
/>
|
2021-09-07 14:55:03 -05:00
|
|
|
}
|
|
|
|
icon="info"
|
|
|
|
button={
|
|
|
|
<Button
|
|
|
|
onClick={openDialog}
|
|
|
|
size={ButtonSize.Small}
|
|
|
|
variant={ButtonVariant.SystemMessage}
|
|
|
|
>
|
2023-03-29 17:03:25 -07:00
|
|
|
{i18n('icu:DeliveryIssue--learnMore')}
|
2021-09-07 14:55:03 -05:00
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
/>
|
2021-05-28 12:11:19 -07:00
|
|
|
{isDialogOpen ? (
|
|
|
|
<DeliveryIssueDialog
|
|
|
|
i18n={i18n}
|
2021-07-27 13:30:41 -07:00
|
|
|
inGroup={inGroup}
|
2021-05-28 12:11:19 -07:00
|
|
|
sender={sender}
|
|
|
|
onClose={closeDialog}
|
|
|
|
/>
|
|
|
|
) : null}
|
2021-09-07 14:55:03 -05:00
|
|
|
</>
|
2021-05-28 12:11:19 -07:00
|
|
|
);
|
|
|
|
}
|