Untitled

mail@pastecode.io avatar
unknown
plain_text
19 days ago
3.7 kB
3
Indexable
Never
Update the below code to move the code inside useeffect() to rfiutil page and call the function  fetchRefTableValue from inside the useeffect(). pass the value ConstantKeys.REF_TABLE.CREATE_RFI_REF_TABLES while calling the function, so the function stayes dynamic.


import BodySection from '@/Layout/BodySection';
import RightSection from '@/Layout/RightSection';
import { useAppState, withPage, Lift, Util, refTables as refTablesSubject } from '@d-lift/core';
import { Page } from '@d-lift/uxcomponents';
import React, { useEffect } from 'react';
import RFIFilters from './Components/RFIFilters';
import RFIRequestForm from './Components/RFIRequestForm';
import './createRfi.scss';
import ConstantKeys from '@/Constants/ConstantKeys';
import RFIUtil from '@/Util/RFIUtil';

const RFIRequest = () => {
    const defaultRFIRequest = {
        title: '',
        description: '',
        questionsList: [{ question: '', description: '' }],
        requestedBy: '',
        neededBy: '',
        offering: '',
        category: [...ConstantKeys.DEFAULT_OPTION.CATEGORY],
        programs: [...ConstantKeys.DEFAULT_OPTION.PROGRAM],
        status: '',
    };

    const [rfiRequest, setRFIRequest] = useAppState('rfiRequest', defaultRFIRequest);
    const [refDataLoaded, setRefDataLoaded] = useAppState('refDataLoaded', false);

    const updateRFIRequest = (newState) => {
        setRFIRequest(newState);
    };

    useEffect(() => {
        if (Util.getSessionData(ConstantKeys.REF_TABLE.CREATE_RFI_REF_TABLES)) {
            setRefDataLoaded(true);
        } else {
            refTablesSubject.subscribe(async (refTableData) => {
                if (refTableData) {
                    setRefDataLoaded(true);
                }
            });
        }
    }, []);

    return (
        <Page ref-table-list="PROGRAM, CATEGORY, OFFERING, STATE">
            {refDataLoaded ? (
                <div className="d-flex">
                    <BodySection>
                        <RFIRequestForm
                            rfiRequest={rfiRequest}
                            updateRFIRequest={updateRFIRequest}
                            resetRFIRequest={() =>
                                updateRFIRequest(defaultRFIRequest)
                            }></RFIRequestForm>
                    </BodySection>
                    <RightSection>
                        <RFIFilters
                            rfiRequest={rfiRequest}
                            updateRFIRequest={updateRFIRequest}></RFIFilters>
                    </RightSection>
                </div>
            ) : (
                <></>
            )}
        </Page>
    );
};

export default withPage(
    {
        Description: 'Make a Request Page',
        ContentManager: true,
        LayoutStyle: 'rfi-dashboard',
    },
    RFIRequest,
);



import { AppContext,Util } from '@d-lift/core';
import ConstantKeys from '@/Constants/ConstantKeys';


class CaseManagementUtil {
    setNotification(type, msg, autoTimeout) {
        let notify = {
            display: true,
            type: type,
            msg: msg,
        };
        AppContext.model.setValue('notify', notify);
        if (type === ConstantKeys.NOTIFICATION.TYPE.SUCCESS && autoTimeout) {
            setTimeout(() => {
                this.resetNotification();
            }, 5000);
        }
    }

    resetNotification() {
        AppContext.model.setValue('notify', undefined);
    }

fetchRefTableValue = (tableName) => {
        
    };

    fetchRefTableContentFromSeesion = (tableName) => {
        return JSON.parse(Util.getSessionData(tableName));
    };
}

const caseManagementUtil = new CaseManagementUtil();
export default caseManagementUtil;
Leave a Comment