mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
import React from 'react';
|
|
import ListSelect from "./ListSelect";
|
|
|
|
export default function DisplayNameList({
|
|
salutation,
|
|
firstName,
|
|
lastName,
|
|
company,
|
|
...restProps
|
|
}) {
|
|
const formats = [
|
|
{ format: '{1} {2} {3}', values: [salutation, firstName, lastName], required: [1] },
|
|
{ format: '{1} {2}', values: [firstName, lastName], required: [] },
|
|
{ format: '{1}, {2}', values: [firstName, lastName], required: [1, 2] },
|
|
{ format: '{1}', values: [company], required: [1] }
|
|
];
|
|
|
|
const formatOptions = formats
|
|
.filter((format) => !format.values.some((value, index) => {
|
|
return !value && format.required.indexOf(index + 1) !== -1;
|
|
}))
|
|
.map((formatOption) => {
|
|
const { format, values } = formatOption;
|
|
let label = format;
|
|
|
|
values.forEach((value, index) => {
|
|
const replaceWith = (value || '');
|
|
label = label.replace(`{${index + 1}}`, replaceWith).trim();
|
|
});
|
|
return { label: label.replace(/\s+/g, " ") };
|
|
});
|
|
|
|
return (
|
|
<ListSelect
|
|
items={formatOptions}
|
|
selectedItemProp={'label'}
|
|
textProp={'label'}
|
|
defaultText={'Select display name as'}
|
|
filterable={false}
|
|
{ ...restProps }
|
|
/>
|
|
);
|
|
} |