Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
3.2 kB
3
Indexable
Never
originalContacts=[
        {
            "firstName": "Divya",
            "lastName": "Nidhi",
            "pocId": "dnidhi@deloitte.com",
            "states": [
                "TN"
            ],
            "offerings": [
                "EE"
            ]
        },
        {
            "firstName": "Haley",
            "lastName": "Stokes",
            "pocId": "hstokes@deloitte.com",
            "states": [
                "ME"
            ],
            "offerings": [
                "EE"
            ]
        },
        {
            "firstName": "Anil",
            "lastName": "Dayanand",
            "pocId": "adayanand@deloitte.com",
            "states": [
                "MI"
            ],
            "offerings": [
                "EE"
            ]
        },
        {
            "firstName": "Mritunjay",
            "lastName": "Kumar",
            "pocId": "mrkumar@deloitte.com",
            "states": [
                "OR"
            ],
            "offerings": [
                "EE"
            ]
        },
        {
            "firstName": "Alex",
            "lastName": "Cronin",
            "pocId": "alcronin@deloitte.com",
            "states": [
                "ALL"
            ],
            "offerings": [
                "ALL"
            ]
        },
        {
            "firstName": "Hari",
            "lastName": "Kallumkal",
            "pocId": "hkallumkal@deloitte.com",
            "states": [
                "FL"
            ],
            "offerings": [
                "EE"
            ]
        },
        {
            "firstName": "Keith",
            "lastName": "Zalaznik",
            "pocId": "kzalaznik@deloitte.com",
            "states": [
                "VA"
            ],
            "offerings": [
                "EE"
            ]
        },]

In the below filtering logic of filtering the contacts from original contacts which have matching stateVal is not working correctly. update the below code logic to filter out the contacts from originalContacts for the contacts having state similar to stateVal and update them in contacts state obj using setContacts



let stateVal="IL" 

const handleStateChange = (stateVal) => {
        setStateResp({ state: stateVal });
        setSelectedStateAnswer(stateVal);

        if (stateVal !== ConstantKeys.DEFAULT_OPTION.LIFT_default) {
            const filteredList = originalContacts.filter((item) => {
                const states = item.state?.split(',');
                return (
                    states?.includes(stateVal) ||
                    !stateVal ||
                    stateVal === ConstantKeys.DEFAULT_OPTION.LIFT_default ||
                    stateVal === ConstantKeys.REF_VALUE.ALL
                );
            });

            setContacts(filteredList);
            fetchSelectedStateDesc(stateVal); //setSelectedStateDescis called inside this func
        } else {
            setContacts(originalContacts);
            setSelectedStateDesc('');
        }
        setShowContacts(true);
    };
Leave a Comment