- updates and fixes;
This commit is contained in:
@@ -36,15 +36,15 @@ const FormFieldRepeaterFaq = ({
|
||||
}
|
||||
|
||||
const selectItem = (e) => {
|
||||
const targetedOption = head(stateOptionsData.filter(o => o.question === e.value));
|
||||
|
||||
const targetedOption = head(stateOptionsData.filter(o => o.value === e.value));
|
||||
console.log('selected:', e, stateOptionsData, targetedOption)
|
||||
if (targetedOption) {
|
||||
setStateFieldData([...stateFieldData, targetedOption]);
|
||||
}
|
||||
}
|
||||
|
||||
const addNewItem = () => {
|
||||
const newItem = { id: null, lookUpDataId: null, question: '', response: '', visible: true };
|
||||
const newItem = { id: null, lookUpDataId: null, title: '', value: '', isVisible: true };
|
||||
setStateFieldData([...stateFieldData, newItem]);
|
||||
}
|
||||
|
||||
@@ -61,8 +61,8 @@ const FormFieldRepeaterFaq = ({
|
||||
|
||||
const editItem = (e, index) => {
|
||||
e.stopPropagation();
|
||||
setQuestion(stateFieldData[index].question);
|
||||
setAnswer(stateFieldData[index].response);
|
||||
setQuestion(stateFieldData[index].title);
|
||||
setAnswer(stateFieldData[index].value);
|
||||
setEditDataIndex(index);
|
||||
setIsVisibleEditDialog(true);
|
||||
}
|
||||
@@ -75,7 +75,7 @@ const FormFieldRepeaterFaq = ({
|
||||
}
|
||||
|
||||
const onChangeEditItem = (value, key) => {
|
||||
if (key === 'question') {
|
||||
if (key === 'title') {
|
||||
setQuestion(value);
|
||||
} else {
|
||||
setAnswer(value)
|
||||
@@ -85,8 +85,8 @@ const FormFieldRepeaterFaq = ({
|
||||
const saveEditDialog = () => {
|
||||
const newData = stateFieldData.map((o, i) => {
|
||||
if (i === editDataIndex) {
|
||||
o.question = question;
|
||||
o.response = answer;
|
||||
o.title = question;
|
||||
o.value = answer;
|
||||
return o
|
||||
} else {
|
||||
return o;
|
||||
@@ -113,7 +113,7 @@ const FormFieldRepeaterFaq = ({
|
||||
const usedExistingValues = useCallback(() => {
|
||||
return stateFieldData
|
||||
.filter(o => o.lookUpDataId)
|
||||
.map(o => o.question)
|
||||
.map(o => o.title)
|
||||
}, [stateFieldData]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -149,9 +149,9 @@ const FormFieldRepeaterFaq = ({
|
||||
<Button type="button" iconPos="left" label={__('Aggiungi', 'gepafin')}
|
||||
icon="pi pi-plus" onClick={addNewItem}/>
|
||||
<Dropdown onChange={(e) => selectItem(e)}
|
||||
optionDisabled={(opt) => usedExistingValues().includes(opt.value)}
|
||||
optionDisabled={(opt) => usedExistingValues().includes(opt.title)}
|
||||
options={stateOptionsData}
|
||||
optionLabel="question"/>
|
||||
optionLabel="title"/>
|
||||
</div>
|
||||
<Accordion activeIndex={0}>
|
||||
{stateFieldData.map((o, i) => <AccordionTab key={i}
|
||||
@@ -165,21 +165,21 @@ const FormFieldRepeaterFaq = ({
|
||||
offLabel=""
|
||||
checked={o.isVisible}
|
||||
onChange={(e) => setChecked(e, i)}/>
|
||||
{o.question}
|
||||
{o.title}
|
||||
</div>
|
||||
<div className="appForm__faqTabItem">
|
||||
<Button icon="pi pi-pencil" severity="success"
|
||||
aria-label="Edit"
|
||||
aria-label={__('Modifica', 'gepafin')}
|
||||
onClick={(e) => editItem(e, i)}/>
|
||||
<Button icon="pi pi-times" severity="danger"
|
||||
aria-label="Cancel"
|
||||
aria-label={__('Cancella', 'gepafin')}
|
||||
onClick={() => removeItem(i)}/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<p className="m-0">
|
||||
{o.response}
|
||||
{o.value}
|
||||
</p>
|
||||
</AccordionTab>)}
|
||||
</Accordion>
|
||||
@@ -192,11 +192,11 @@ const FormFieldRepeaterFaq = ({
|
||||
<div className="appPage__spacer"></div>
|
||||
<div className="appForm__field">
|
||||
<label>{__('Titolo FAQ', 'gepafin')}</label>
|
||||
<InputText value={question} onChange={(e) => onChangeEditItem(e.target.value, 'question')}/>
|
||||
<InputText value={question} onChange={(e) => onChangeEditItem(e.target.value, 'title')}/>
|
||||
</div>
|
||||
<div className="appForm__field">
|
||||
<label>{__('Risposta', 'gepafin')}</label>
|
||||
<InputTextarea value={answer} onChange={(e) => onChangeEditItem(e.target.value, 'response')}
|
||||
<InputTextarea value={answer} onChange={(e) => onChangeEditItem(e.target.value, 'value')}
|
||||
rows={5}
|
||||
cols={30}/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user