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
|
|
|
|
|
2024-03-28 22:20:45 +00:00
|
|
|
import React, { useCallback } from 'react';
|
2020-07-29 23:20:05 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { LocalizerType } from '../../types/Util';
|
|
|
|
import type { ConversationType } from '../../state/ducks/conversations';
|
2021-09-07 19:55:03 +00:00
|
|
|
import { SystemMessage } from './SystemMessage';
|
2020-09-08 19:56:10 +00:00
|
|
|
import { Emojify } from './Emojify';
|
2021-10-26 19:15:33 +00:00
|
|
|
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';
|
2020-07-29 23:20:05 +00:00
|
|
|
|
2021-01-14 18:07:05 +00:00
|
|
|
export type PropsType = {
|
2020-07-29 23:20:05 +00:00
|
|
|
change: ProfileNameChangeType;
|
|
|
|
changedContact: ConversationType;
|
|
|
|
i18n: LocalizerType;
|
2024-03-28 22:20:45 +00:00
|
|
|
onOpenEditNicknameAndNoteModal: (contactId: string) => void;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2020-07-29 23:20:05 +00:00
|
|
|
|
2024-03-26 19:48:33 +00:00
|
|
|
export function ProfileChangeNotification({
|
|
|
|
change,
|
|
|
|
changedContact,
|
|
|
|
i18n,
|
|
|
|
onOpenEditNicknameAndNoteModal,
|
|
|
|
}: PropsType): JSX.Element {
|
2020-07-29 23:20:05 +00:00
|
|
|
const message = getStringForProfileChange(change, changedContact, i18n);
|
2024-03-28 22:20:45 +00:00
|
|
|
const { id: contactId } = changedContact;
|
|
|
|
|
|
|
|
const handleOpenEditNicknameAndNoteModal = useCallback(() => {
|
|
|
|
onOpenEditNicknameAndNoteModal(contactId);
|
|
|
|
}, [contactId, onOpenEditNicknameAndNoteModal]);
|
2020-07-29 23:20:05 +00:00
|
|
|
|
2024-03-26 19:48:33 +00:00
|
|
|
return (
|
|
|
|
<SystemMessage
|
|
|
|
icon="profile"
|
|
|
|
contents={<Emojify text={message} />}
|
|
|
|
button={
|
2024-04-03 22:41:13 +00:00
|
|
|
(changedContact.nicknameGivenName != null ||
|
|
|
|
changedContact.nicknameFamilyName != null) && (
|
2024-03-26 19:48:33 +00:00
|
|
|
<Button
|
2024-03-28 22:20:45 +00:00
|
|
|
onClick={handleOpenEditNicknameAndNoteModal}
|
2024-03-26 19:48:33 +00:00
|
|
|
size={ButtonSize.Small}
|
|
|
|
variant={ButtonVariant.SystemMessage}
|
|
|
|
>
|
|
|
|
{i18n('icu:update')}
|
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
2020-07-29 23:20:05 +00:00
|
|
|
}
|