Untitled

mail@pastecode.io avatar
unknown
plain_text
18 days ago
4.9 kB
2
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 './create-rfi.scss';
import ConstantKeys from '@/Constants/ConstantKeys';
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 [programsList, setProgramsList] = useState([]);

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

    const getRefTableValueFromSession = (tableName) => {
        return JSON.parse(Util.getSessionData(ConstantKeys.REF_TABLE[tableName]));
    };

    useEffect(() => {
        const fetchRefTableContent = () => {
            let refTableContent = getRefTableValueFromSession('GET_OFFERING');
            console.log('refTableContent:', refTableContent);
            // Update the state with the initial refTableContent if needed
        };

        fetchRefTableContent();
    }, []);

    const handleOfferingChange = (offering) => {
        let refTableContent = getRefTableValueFromSession('GET_OFFERING');
        let filteredPrograms = refTableContent.PROGRAM.filter(program => program[offering] === 'Y');
        setProgramsList(filteredPrograms);
        updateRFIRequest({ ...rfiRequest, offering });
    };

    return (
        <Page ref-table-list="PROGRAM, CATEGORY, OFFERING">
            <div className="d-flex">
                <BodySection>
                    <RFIRequestForm
                        rfiRequest={rfiRequest}
                        updateRFIRequest={updateRFIRequest}
                        resetRFIRequest={defaultRFIRequest}
                        programsList={programsList}
                        handleOfferingChange={handleOfferingChange}></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 {
    Button,
    Checkbox,
    Column,
    Grid,
    Header,
    Row,
    Textarea,
    Textbox,
    Label,
    Spinner,
    Dropdown
} from '@d-lift/uxcomponents';
import PropTypes from 'prop-types';
import React from 'react';
import Questionnaire from './Questionnaire';
import webService from '@/Services/WebService';
import ConstantKeys from '@/Constants/ConstantKeys';
import { Lift } from '@d-lift/core';

const RFIRequestForm = ({ rfiRequest, updateRFIRequest, resetRFIRequest, programsList, handleOfferingChange }) => {
    const generateUniqueId = () => {
        return Math.floor(Math.random() * 100 + 1);
    };

    const handleAddQuestion = () => {
        let updatedQuestions = [
            ...rfiRequest.questionsList,
            { id: generateUniqueId(), question: '', description: '' },
        ];
        updateRFIRequest({ ...rfiRequest, questionsList: updatedQuestions });
    };

    const handleDeleteQuestion = (id) => {
        const questionToDelete = rfiRequest.questionsList.find((q) => q.id === id);

        if (questionToDelete) {
            let updatedQuestions = rfiRequest.questionsList.filter((q) => q.id !== id);
            updateRFIRequest({ ...rfiRequest, questionsList: updatedQuestions });
        } else {
            deleteQuestionFromDatabase(id);
        }
    };

    const deleteQuestionFromDatabase = async (id) => {
        try {
            const response = await webService.deleteRFIQuesion(`/questions/${id}`, {
                requestBody: {
                    questionId: id,
                    requestId: 1,
                },
            });

            updateRFIRequest({ ...rfiRequest, questionsList: response.data.updatedQuestions });
        } catch (error) {
            console.error('Failed to delete the question from the database', error);
        }
    };

    const validateForm = () => {
        const requiredFields = ['title', 'reqDescription', 'offering'];
        for (let field of requiredFields


Leave a Comment