podkrepi-bg / frontend

Charity platform https://podkrepi.bg Docs https://docs.podkrepi.bg
https://podkrepi.bg
MIT License
177 stars 88 forks source link

Fix id after choosing a campaign (Admin panel) #1891

Closed ani-kalpachka closed 3 months ago

ani-kalpachka commented 4 months ago

Fixed id after choosing a campain in recurring donations in Admin panel:

Before After
image image

The id is set in handleCampaignSelected function when the user chooses a campaign. The issue was caused by setting an initail value on sourceVault when the id is already present, so I reset it to '' in the object.

ani-kalpachka commented 4 months ago

As I understand it, sourceVault: data?.sourceVault.idsets the inital value if the id is present. The same id is set for the second time when a campaign is chosen from the dropdown in this block of code:

handleCampaignSelected={(campaign) => {
    campaigns?.forEach((c) => {
        if (c.id === campaign && c.vaults) {
            setFieldValue('sourceVault', c.vaults[0].id)
         }
    })
}}

I thought we dont need the first initail setting of the value and it should be handled in the handleCampaignSelected() function. This approach fixes the issue and seems not to cause unwanted side effects. It may be better approuches though. If you have some concerns and other better suggestions how to fix the issue, please advice.

@slavcho