Untitled

mail@pastecode.io avatar
unknown
plain_text
23 days ago
6.0 kB
1
Indexable
Never
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, updateRFIRequest }) => {
    const offeringList = [
        { DESCRIPTION: 'Eligibility and Enrollment', CODE: 'EE' },
        { DESCRIPTION: 'Child Support', CODE: 'CS' },
        { DESCRIPTION: 'Child Welfare', CODE: 'CW' },
    ];

    const categoryList = [
        { label: 'ALL', value: 'AL' },
        { label: 'Eligibility', value: 'EL' },
        { label: 'Front Office', value: 'FO' },
        { label: 'Interfaces', value: 'IN' },
        { label: 'Reports', value: 'RE' },
        { label: 'General/Other', value: 'GO' },
    ];
    useAppState('categoryList', categoryList);

    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 === 'AL') {
            updatedCategory = ['AL'];
        } else {
            if (updatedCategory.includes('AL')) {
                updatedCategory = updatedCategory.filter((item) => item !== 'AL');
            }
            if (updatedCategory.includes(selectedCategory)) {
                updatedCategory = updatedCategory.filter((item) => item !== selectedCategory);
            } else {
                updatedCategory.push(selectedCategory);
            }
        }

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

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

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

    return (
        <>
            <Selectbox
                id="requestedBy"
                labelKey="requesting_as"
                model="rfiRequest.requestedBy"
                className="w-100"
                placeholder="-Select A State -"
                list="stateList"
                optionLabel={ConstantKeys.REF_TABLE_COLS.DESCRIPTION}
                optionValue={ConstantKeys.REF_TABLE_COLS.CODE}></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"
                        monthDropdown
                        yearDropdown
                        required></Date>
                </div>
            </Group>

            <Selectbox
                model="rfiRequest.offering"
                labelKey="offering"
                list={offeringList}
                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">
                        {categoryList.map((item) => {
                            return (
                                <Checkbox
                                    key={item.value}
                                    text={item.label}
                                    value={item.value}
                                    checked={rfiRequest.category.includes(item.value)}
                                    change={handleCategoryChange}
                                />
                            );
                        })}
                    </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((item) => {
                            return (
                                <Checkbox
                                    key={item.CODE}
                                    text={item.DESCRIPTION}
                                    value={item.CODE}
                                    checked={rfiRequest.programs.includes(item.CODE)}
                                    change={handleProgramChange}
                                />
                            );
                        })}
                    </CheckboxGroup>
                </div>
            </div>
        </>
    );
};

RFIFilters.propTypes = {
    rfiRequest: PropTypes.object.isRequired,
    updateRFIRequest: PropTypes.func.isRequired,
};

export default RFIFilters;
Leave a Comment