Untitled

mail@pastecode.io avatar
unknown
plain_text
15 days ago
10 kB
1
Indexable
Never
import BodySection from '@/Layout/BodySection';
import RightSection from '@/Layout/RightSection';
import { useAppState, withPage, Lift, Util } from '@d-lift/core';
import { Page } from '@d-lift/uxcomponents';
import React, { useEffect, useState } from 'react';
import RFIFilters from './Components/RFIFilters';
import RFIRequestForm from './Components/RFIRequestForm';
import './createRfi.scss';
import ConstantKeys from '@/Constants/ConstantKeys';
import webService from '@/Services/WebService';
import RFIUtil from '@/Util/RFIUtil';

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

    const [rfiRequest, setRFIRequest] = useAppState('rfiRequest', defaultRFIRequest);
    const [filteredStates, setFilteredStates] = useState([]);
    const [filteredOfferings, setFilteredOfferings] = useState([]);

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

    useEffect(() => {
        const refTableContent = JSON.parse(
            Util.getSessionData(ConstantKeys.REF_TABLE.GET_OFFERING),
        );

        const loginDetails = getLoginData();

        if (refTableContent && loginDetails) {
            const stateCodes = loginDetails.map((detail) => detail.state);
            const filteredStateValues = refTableContent.STATE.filter((state) =>
                stateCodes.includes(state.CODE),
            );

            setFilteredStates(filteredStateValues);
        }
    }, []);

    const getLoginData = () => {
        // const loginDetails = webService.getLoginDetails({
        //     requestBody: '',
        // });
        return [
            {
                state: 'SS',
                offering: ['EE'],
            },
            {
                state: 'WI',
                offering: ['EE','CW'],
            },
            {
                state: 'ND',
                offering: ['EE', 'EF'],
            },
            {
                state: 'MD',
                offering: ['CW'],
            },
            {
                state: 'WY',
                offering: ['CW', 'EF'],
            },
            {
                state: 'AB',
                offering: ['EE','CW'],
            },
            {
                state: 'ST',
                offering: ['EE', 'EF'],
            },
            {
                state: 'IN',
                offering: ['EE', 'EF', 'CW'],
            },
            {
                state: 'AL',
                offering: ['EE', 'EF', 'CW'],
            },
            {
                state: 'AK',
                offering: ['EE', 'EF', 'CW'],
            },
            {
                state: 'AS',
                offering: ['EE', 'EF', 'CW'],
            },
        ];
    };

    const handleStateChange = (event) => {
        const selectedState = event.target.value;
        const loginDetails = getLoginData();

        const selectedStateDetails = loginDetails.find(detail => detail.state === selectedState);

        if (selectedStateDetails) {
            const availableOfferings = selectedStateDetails.offering;
            setFilteredOfferings(availableOfferings);
            updateRFIRequest({
                ...rfiRequest,
                requestedBy: selectedState,
                offering: availableOfferings.length ? availableOfferings[0] : ''
            });
        }
    };

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

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




import ConstantKeys from '@/Constants/ConstantKeys';
import { useAppState } from '@d-lift/core';
import { CheckboxGroup, Date, Group, Label, Selectbox, Checkbox } from '@d-lift/uxcomponents';
import React from 'react';
import PropTypes from 'prop-types';

const RFIFilters = ({ rfiRequest, filteredStates, filteredOfferings, updateRFIRequest, onStateChange }) => {
    const categoryRefTable = [
        { DESCRIPTION: 'ALL', CODE: 'ALL' },
        { DESCRIPTION: 'Eligibility', CODE: 'EG' },
        { DESCRIPTION: 'Front Office', CODE: 'FO' },
        { DESCRIPTION: 'Interfaces', CODE: 'IF' },
        { DESCRIPTION: 'Reports', CODE: 'RP' },
        { DESCRIPTION: 'General/Other', CODE: 'GO' },
    ];
    useAppState('categoryList', categoryRefTable);

    const programRefTable = [
        { DESCRIPTION: 'ALL', CODE: 'ALL' },
        { DESCRIPTION: 'AU', CODE: 'AU' },
        { DESCRIPTION: 'MA', CODE: 'MA' },
        { DESCRIPTION: 'LIHEAP', CODE: 'LIHEAP' },
        { DESCRIPTION: 'CC', CODE: 'CC' },
        { DESCRIPTION: 'PIPP', CODE: 'PIPP' },
    ];
    useAppState('programList', programRefTable);

    // Handler for category selection
    const handleCategoryChange = (event) => {
        const selectedCategory = event.target.value;
        let updatedCategory = [...rfiRequest.category];

        if (selectedCategory === 'ALL') {
            updatedCategory = ['ALL'];
        } else if (updatedCategory.includes('ALL')) {
            updatedCategory = updatedCategory.filter((item) => item !== 'ALL');
        }

        const newList = { ...rfiRequest, category: updatedCategory };
        updateRFIRequest(newList);
    };

    // Handler for program selection
    const handleProgramChange = (event) => {
        const value = event.target.value;
        let selectedPrograms = [...rfiRequest.programs];

        if (value === 'ALL') {
            selectedPrograms = ['ALL'];
        } else if (selectedPrograms.includes('ALL')) {
            selectedPrograms = selectedPrograms.filter((program) => program !== 'ALL');
        }
        const newList = { ...rfiRequest, programs: selectedPrograms };
        updateRFIRequest(newList);
    };

    return (
        <>
            <Label className="pt-3 mandatory_field" labelKey="requesting_as"></Label>

            <Selectbox
                id="requestedBy"
                model="rfiRequest.requestedBy"
                className="w-100"
                defaultOptionLabelKey="select_state"
                list={filteredStates}
                optionLabel={ConstantKeys.REF_TABLE_COLS.DESCRIPTION}
                optionValue={ConstantKeys.REF_TABLE_COLS.CODE}
                defaultOption="true"
                required
                onChange={onStateChange}></Selectbox>

            <Group width="3,9">
                <Label className="pt-4" labelKey="needed_by"></Label>
                <div className="ux-rfi-calendar">
                    <Date
                        id="neededByDate"
                        model="rfiRequest.neededBy"
                        // className="mandatory_field"
                        // required
                        monthDropdown
                        yearDropdown></Date>
                </div>
            </Group>

            <Selectbox
                model="rfiRequest.offering"
                labelKey="offering"
                list={filteredOfferings.map(code => ({
                    CODE: code,
                    DESCRIPTION: code === 'EE' ? 'Eligibility and Enrollment' : 
                                code === 'CS' ? 'Child Support' : 
                                code === 'CW' ? 'Child Welfare' : 'Unknown'
                }))}
                optionLabel={ConstantKeys.REF_TABLE_COLS.DESCRIPTION}
                optionValue={ConstantKeys.REF_TABLE_COLS.CODE}
                className="ux-w-100 pt-3"
            />

            <div className="ux-rfi-grey-border w-100 mt-3">
                <Label labelKey="category"></Label>
                <div className="ux-rfi-grey-border">
                    <CheckboxGroup model="rfiRequest.category">
                        {categoryRefTable.map((cateegoryItem, index) => (
                            <Checkbox
                                id={'category-item-' + index}
                                text={cateegoryItem[ConstantKeys.REF_TABLE_COLS.DESCRIPTION]}
                                value={cateegoryItem[ConstantKeys.REF_TABLE_COLS.CODE]}
                                change={(event) => handleCategoryChange(event)}></Checkbox>
                        ))}
                    </CheckboxGroup>
                </div>
            </div>
            <div className="ux-rfi-grey-border w-100 mt-4 pt-1">
                <Label labelKey="program"></Label>
                <div className="ux-rfi-grey-border">
                    <CheckboxGroup model="rfiRequest.programs">
                        {programRefTable.map((programsItem, index) => (
                            <Checkbox
                                id={'program-item-' + index}
                                text={programsItem[ConstantKeys.REF_TABLE_COLS.DESCRIPTION]}
                                value={programsItem[ConstantKeys.REF_TABLE_COLS.CODE]}
                                change={(event) => handleProgramChange(event)}></Checkbox>
                        ))}
                    </CheckboxGroup>
                </div>
            </div>
        </>
    );
};

RFIFilters.propTypes = {
    rfiRequest: PropTypes.object.isRequired,
    filteredStates: PropTypes.array.isRequired,
    filteredOfferings: PropTypes.array.isRequired,
    updateRFIRequest: PropTypes.func.isRequired,
    onStateChange: PropTypes.func.isRequired,
};

export default RFIFilters;
Leave a Comment