From 9dc101d3f6c5726b8bbfb1122d5dd801488d154b Mon Sep 17 00:00:00 2001 From: Nuwan Date: Wed, 28 Feb 2024 19:48:52 +0530 Subject: [PATCH] fix instrument proficiency chage update the state correctly of the instrument list when proficiency is changed --- jam-ui/src/components/page/JKEditProfile.js | 22 ++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/jam-ui/src/components/page/JKEditProfile.js b/jam-ui/src/components/page/JKEditProfile.js index 798f2516d..bb3a0a08c 100644 --- a/jam-ui/src/components/page/JKEditProfile.js +++ b/jam-ui/src/components/page/JKEditProfile.js @@ -250,20 +250,32 @@ function JKEditProfile() { }; const handleInstrumentProficiencyChange = (option, musicInstrument) => { + let updatedInstruments = []; const userInstrument = getValues('instruments').find(instrument => instrument.instrument_id === musicInstrument.id); if (!userInstrument) { - const updatedInstruments = [...getValues('instruments'), { ...musicInstrument, proficiency_level: option.value }]; - setValue('instruments', updatedInstruments); + updatedInstruments = [...getValues('instruments'), { ...musicInstrument, proficiency_level: option.value }]; + //setValue('instruments', updatedInstruments); } else { - const updatedInstruments = getValues('instruments').map(instrument => { + updatedInstruments = getValues('instruments').map(instrument => { if (instrument.instrument_id === musicInstrument.id) { instrument.proficiency_level = option.value; } 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(); };