78 lines
1.8 KiB
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';
import { Pencil } from '@buffetjs/icons';
import { Text, IconLinks } from '@buffetjs/core';
import { CustomRow } from '@buffetjs/styles';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { getTrad } from '../../utils';
2021-02-02 16:08:16 +01:00
const LocaleSettingsPage = ({ locale, onDelete, onEdit }) => {
const { formatMessage } = useIntl();
2021-02-04 16:00:04 +01:00
const links = [];
if (onEdit) {
links.push({
icon: (
2021-02-08 13:47:43 +01:00
<span aria-label={formatMessage({ id: getTrad('Settings.list.actions.edit') })}>
2021-02-04 16:00:04 +01:00
<Pencil fill="#0e1622" />
</span>
),
onClick: () => onEdit(locale),
});
}
if (onDelete) {
links.push({
icon: !locale.isDefault ? (
2021-02-08 13:47:43 +01:00
<span aria-label={formatMessage({ id: getTrad('Settings.list.actions.delete') })}>
2021-02-04 16:00:04 +01:00
<FontAwesomeIcon icon="trash-alt" />
</span>
) : null,
onClick: e => {
e.stopPropagation();
onDelete(locale);
},
2021-02-04 16:00:04 +01:00
});
}
return (
<CustomRow onClick={() => onEdit(locale)}>
<td>
<Text>{locale.code}</Text>
</td>
<td>
2021-02-09 16:55:57 +01:00
<Text fontWeight="semiBold">{locale.name}</Text>
</td>
<td>
<Text>
{locale.isDefault
? formatMessage({ id: getTrad('Settings.locales.row.default-locale') })
: null}
</Text>
</td>
<td>
2021-02-04 16:00:04 +01:00
<IconLinks links={links} />
</td>
</CustomRow>
);
};
2021-02-04 16:00:04 +01:00
LocaleSettingsPage.defaultProps = {
onDelete: undefined,
onEdit: undefined,
};
LocaleSettingsPage.propTypes = {
locale: PropTypes.shape({
isDefault: PropTypes.bool,
2021-02-09 16:55:57 +01:00
name: PropTypes.string,
code: PropTypes.string.isRequired,
}).isRequired,
2021-02-04 16:00:04 +01:00
onDelete: PropTypes.func,
onEdit: PropTypes.func,
};
export default LocaleSettingsPage;