fix instrument proficiency chage
update the state correctly of the instrument list when proficiency is changed
This commit is contained in:
parent
1a11cc331c
commit
9dc101d3f6
|
|
@ -250,20 +250,32 @@ function JKEditProfile() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleInstrumentProficiencyChange = (option, musicInstrument) => {
|
const handleInstrumentProficiencyChange = (option, musicInstrument) => {
|
||||||
|
let updatedInstruments = [];
|
||||||
const userInstrument = getValues('instruments').find(instrument => instrument.instrument_id === musicInstrument.id);
|
const userInstrument = getValues('instruments').find(instrument => instrument.instrument_id === musicInstrument.id);
|
||||||
if (!userInstrument) {
|
if (!userInstrument) {
|
||||||
const updatedInstruments = [...getValues('instruments'), { ...musicInstrument, proficiency_level: option.value }];
|
updatedInstruments = [...getValues('instruments'), { ...musicInstrument, proficiency_level: option.value }];
|
||||||
setValue('instruments', updatedInstruments);
|
//setValue('instruments', updatedInstruments);
|
||||||
} else {
|
} else {
|
||||||
const updatedInstruments = getValues('instruments').map(instrument => {
|
updatedInstruments = getValues('instruments').map(instrument => {
|
||||||
if (instrument.instrument_id === musicInstrument.id) {
|
if (instrument.instrument_id === musicInstrument.id) {
|
||||||
instrument.proficiency_level = option.value;
|
instrument.proficiency_level = option.value;
|
||||||
}
|
}
|
||||||
return instrument;
|
return instrument;
|
||||||
});
|
});
|
||||||
setValue('instruments', updatedInstruments);
|
//setValue('instruments', updatedInstruments);
|
||||||
}
|
}
|
||||||
forceUpdate();
|
setValue('instruments', updatedInstruments);
|
||||||
|
|
||||||
|
const updatedMusicInstruments = musicInstruments.map(instrument => {
|
||||||
|
if (instrument.id === musicInstrument.id) {
|
||||||
|
instrument.proficiency_level = option.value;
|
||||||
|
}
|
||||||
|
return instrument;
|
||||||
|
});
|
||||||
|
|
||||||
|
setMusicInstruments(updatedMusicInstruments);
|
||||||
|
|
||||||
|
//forceUpdate();
|
||||||
handleChange();
|
handleChange();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue