2021-01-29 17:22:32 +01:00
|
|
|
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 }) => {
|
2021-01-29 17:22:32 +01:00
|
|
|
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,
|
2021-02-11 10:35:22 +01:00
|
|
|
onClick: e => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onDelete(locale);
|
|
|
|
|
},
|
2021-02-04 16:00:04 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-29 17:22:32 +01:00
|
|
|
return (
|
2021-02-11 10:35:22 +01:00
|
|
|
<CustomRow onClick={() => onEdit(locale)}>
|
2021-01-29 17:22:32 +01:00
|
|
|
<td>
|
|
|
|
|
<Text>{locale.code}</Text>
|
|
|
|
|
</td>
|
|
|
|
|
<td>
|
2021-02-09 16:55:57 +01:00
|
|
|
<Text fontWeight="semiBold">{locale.name}</Text>
|
2021-01-29 17:22:32 +01:00
|
|
|
</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} />
|
2021-01-29 17:22:32 +01:00
|
|
|
</td>
|
|
|
|
|
</CustomRow>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2021-02-04 16:00:04 +01:00
|
|
|
LocaleSettingsPage.defaultProps = {
|
|
|
|
|
onDelete: undefined,
|
|
|
|
|
onEdit: undefined,
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-29 17:22:32 +01:00
|
|
|
LocaleSettingsPage.propTypes = {
|
|
|
|
|
locale: PropTypes.shape({
|
|
|
|
|
isDefault: PropTypes.bool,
|
2021-02-09 16:55:57 +01:00
|
|
|
name: PropTypes.string,
|
2021-01-29 17:22:32 +01:00
|
|
|
code: PropTypes.string.isRequired,
|
|
|
|
|
}).isRequired,
|
2021-02-04 16:00:04 +01:00
|
|
|
onDelete: PropTypes.func,
|
|
|
|
|
onEdit: PropTypes.func,
|
2021-01-29 17:22:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default LocaleSettingsPage;
|