signal-desktop/ts/components/conversation/ProfileChangeNotification.tsx

53 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import React, { useCallback } from 'react';
import type { LocalizerType } from '../../types/Util';
import type { ConversationType } from '../../state/ducks/conversations';
import { SystemMessage } from './SystemMessage';
import { Emojify } from './Emojify';
import type { ProfileNameChangeType } from '../../util/getStringForProfileChange';
import { getStringForProfileChange } from '../../util/getStringForProfileChange';
2024-03-26 19:48:33 +00:00
import { Button, ButtonSize, ButtonVariant } from '../Button';
export type PropsType = {
change: ProfileNameChangeType;
changedContact: ConversationType;
i18n: LocalizerType;
onOpenEditNicknameAndNoteModal: (contactId: string) => void;
};
2024-03-26 19:48:33 +00:00
export function ProfileChangeNotification({
change,
changedContact,
i18n,
onOpenEditNicknameAndNoteModal,
}: PropsType): JSX.Element {
const message = getStringForProfileChange(change, changedContact, i18n);
const { id: contactId } = changedContact;
const handleOpenEditNicknameAndNoteModal = useCallback(() => {
onOpenEditNicknameAndNoteModal(contactId);
}, [contactId, onOpenEditNicknameAndNoteModal]);
2024-03-26 19:48:33 +00:00
return (
<SystemMessage
icon="profile"
contents={<Emojify text={message} />}
button={
(changedContact.nicknameGivenName != null ||
changedContact.nicknameFamilyName != null) && (
2024-03-26 19:48:33 +00:00
<Button
onClick={handleOpenEditNicknameAndNoteModal}
2024-03-26 19:48:33 +00:00
size={ButtonSize.Small}
variant={ButtonVariant.SystemMessage}
>
{i18n('icu:update')}
</Button>
)
}
/>
);
}