bigbuffet-rw/app/soapbox/features/ui/components/profile-fields-panel.tsx

93 lines
2.9 KiB
TypeScript
Raw Normal View History

import classNames from 'clsx';
2022-04-29 19:05:39 -07:00
import React from 'react';
2022-04-29 19:37:09 -07:00
import { defineMessages, useIntl, FormattedMessage, FormatDateOptions } from 'react-intl';
2022-04-29 19:51:48 -07:00
import { Widget, Stack, HStack, Icon, Text } from 'soapbox/components/ui';
2022-11-16 05:32:32 -08:00
import BundleContainer from 'soapbox/features/ui/containers/bundle-container';
2022-04-29 19:37:09 -07:00
import { CryptoAddress } from 'soapbox/features/ui/util/async-components';
import type { Account, Field } from 'soapbox/types/entities';
const getTicker = (value: string): string => (value.match(/\$([a-zA-Z]*)/i) || [])[1];
const isTicker = (value: string): boolean => Boolean(getTicker(value));
2022-04-29 19:05:39 -07:00
2022-04-29 19:37:09 -07:00
const messages = defineMessages({
linkVerifiedOn: { id: 'account.link_verified_on', defaultMessage: 'Ownership of this link was checked on {date}' },
account_locked: { id: 'account.locked_info', defaultMessage: 'This account privacy status is set to locked. The owner manually reviews who can follow them.' },
deactivated: { id: 'account.deactivated', defaultMessage: 'Deactivated' },
bot: { id: 'account.badges.bot', defaultMessage: 'Bot' },
});
const dateFormatOptions: FormatDateOptions = {
month: 'short',
day: 'numeric',
year: 'numeric',
hour12: true,
hour: 'numeric',
2022-04-29 19:37:09 -07:00
minute: '2-digit',
};
interface IProfileField {
field: Field,
}
2022-04-29 19:05:39 -07:00
2022-04-29 19:37:09 -07:00
/** Renders a single profile field. */
const ProfileField: React.FC<IProfileField> = ({ field }) => {
const intl = useIntl();
if (isTicker(field.name)) {
return (
<BundleContainer fetchComponent={CryptoAddress}>
{Component => (
<Component
ticker={getTicker(field.name).toLowerCase()}
address={field.value_plain}
/>
)}
</BundleContainer>
);
}
return (
<dl>
<dt title={field.name}>
<Text weight='bold' tag='span' dangerouslySetInnerHTML={{ __html: field.name_emojified }} />
</dt>
<dd
2022-04-29 19:51:48 -07:00
className={classNames({ 'text-success-500': field.verified_at })}
2022-04-29 19:37:09 -07:00
title={field.value_plain}
>
2022-04-29 19:51:48 -07:00
<HStack space={2} alignItems='center'>
{field.verified_at && (
<span className='flex-none' title={intl.formatMessage(messages.linkVerifiedOn, { date: intl.formatDate(field.verified_at, dateFormatOptions) })}>
<Icon src={require('@tabler/icons/check.svg')} />
2022-04-29 19:51:48 -07:00
</span>
)}
2022-04-29 19:37:09 -07:00
<Text className='break-words overflow-hidden' tag='span' dangerouslySetInnerHTML={{ __html: field.value_emojified }} />
2022-04-29 19:51:48 -07:00
</HStack>
2022-04-29 19:37:09 -07:00
</dd>
</dl>
);
};
2022-04-29 19:05:39 -07:00
interface IProfileFieldsPanel {
account: Account,
}
/** Custom profile fields for sidebar. */
const ProfileFieldsPanel: React.FC<IProfileFieldsPanel> = ({ account }) => {
return (
<Widget title={<FormattedMessage id='profile_fields_panel.title' defaultMessage='Profile fields' />}>
2022-04-29 19:37:09 -07:00
<Stack space={4}>
{account.fields.map((field, i) => (
<ProfileField field={field} key={i} />
2022-04-29 19:05:39 -07:00
))}
</Stack>
</Widget>
);
};
export default ProfileFieldsPanel;