Advertisement
Tinku0

FLUENT UI FORM

May 22nd, 2024 (edited)
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 7.84 KB | Source Code | 0 0
  1. import './CreateBusinessObjective.css';
  2. import Upload from '../../common/FileUpload/Upload';
  3. import info from "../../assets/images/Info.svg"
  4.  
  5. import { useEffect, useState } from 'react';
  6. import { DefaultButton, Dropdown, DropdownMenuItemType, Icon, Label, PrimaryButton, Stack, TextField } from '@fluentui/react';
  7.  
  8. import FileUpload from '../../common/FileUpload/FileUpload';
  9.  
  10. import React from 'react';
  11. import { getAllBusinessObjectiveOptions } from '../../service/BusinessObjectiveServices';
  12. import { Logger } from '@azure/msal-browser';
  13.  
  14.  
  15.  
  16. interface Field {
  17.   label: string;
  18.   value: string;
  19.   onChange: (event: React.ChangeEvent<HTMLInputElement> | React.ChangeEvent<HTMLSelectElement>) => void;
  20.   placeholder?: string;
  21.   options?: string[];
  22. }
  23.  
  24. interface CreateBusinessObjectiveProps {
  25.   isOpen: boolean;
  26.   onClose: () => void;
  27.   assetId?:string
  28. }
  29.  
  30. const formTokens = { childrenGap: 2 };
  31. const buttonStackTokens = { childrenGap: 1 };
  32.  
  33. const dropdownControlledExampleOptions = [
  34.   { key: '1998', text: '1998', itemType: DropdownMenuItemType.Header },
  35.   { key: '1999', text: '1999' },
  36.   { key: '2000', text: '2000' },
  37.   { key: '2001', text: '2001' }
  38. ];
  39.  
  40.  
  41. const CreateBusinessObjective: React.FC<CreateBusinessObjectiveProps> = ({ isOpen, onClose,assetId }) => {}
  42.   const [objectiveName, setObjectiveName] = useState<string>('');
  43.   const [selectedOption, setSelectedOption] = useState<string>('');
  44.   const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
  45.   const [ objectiveOptions, setObjectiveOptions ] = useState({
  46.     fiscalYearOptions: [],
  47.     ownerOptions: [],
  48.     csaOptions: [],
  49.     industryOptions: [],
  50.     geoOuOptions: [],
  51.     segmentOptions: []
  52.   })
  53.  
  54.  
  55.  
  56.   const [formState , setFormState]: any = useState({
  57.    
  58.     businessObjectives: '',
  59.     fiscalYear: undefined,
  60.     owner: undefined,
  61.     kpi: '',
  62.     csa: undefined,
  63.     industry: undefined,
  64.     geoOu: undefined,
  65.     segment: undefined,
  66.   });
  67.  
  68.   const handleInputChange = (field : any, value : any) => {
  69.     setFormState((prevState : any) => ({ ...prevState, [field]: value }));
  70.   };
  71.  
  72.   const handleSubmit = () => {
  73.     const formData = {
  74.       businessObjectives: formState.businessObjectives,
  75.       fiscalYear: formState.fiscalYear ? formState.fiscalYear.key : '',
  76.       owner: formState.owner ? formState.owner.key : '',
  77.       kpi: formState.kpi,
  78.       csa: formState.csa ? formState.csa.key : '',
  79.       industry: formState.industry ? formState.industry.key : '',
  80.       geoOu: formState.geoOu ? formState.geoOu.key : '',
  81.       segment: formState.segment ? formState.segment.key : ''
  82.     };
  83.  
  84.  
  85.     console.log('Form Data:', formData);
  86.     // Process formData here, e.g., send to an API or update the state
  87.     // call API for post data here
  88.   };
  89.  
  90.   useEffect(() => {
  91.     try {
  92.       const objectiveOptions = getAllBusinessObjectiveOptions();
  93.       objectiveOptions.then((data) => { console.log(data) })
  94.       setObjectiveOptions((prevState) => ({
  95.         ...prevState,
  96.         fiscalYearOptions: data.fiscalYear.length ? data.fiscalYear.map((option) => { return { text: option.name, key: option.value } }) : [],
  97.         ownerOptions: data.owner.length ? data.owner.map((option) => { return { text: option.name, key: option.value } }) : [],
  98.         csaOptions: data.solutionAreas.length ? data.solutionAreas.map((option) => { return { text: option.name, key: option.value } }) : [],
  99.         industryOptions: data.industry.length ? data.industry.map((option) => { return { text: option.name, key: option.value } }) : [],
  100.         geoOuOptions: data.geography.length ? data.geography.map((option) => { return { text: option.name, key: option.value } }) : [],
  101.         segmentOptions: data.segment.length ? data.segment.map((option) => { return { text: option.name, key: option.value } }): []
  102.       }))
  103.     } catch (error) {
  104.       console.log(error)
  105.     }
  106.   },[])
  107.  
  108.   return (
  109.     <>
  110.       {isOpen && (
  111.         <div className="overlay" ></div>
  112.       )}
  113.       <div className={`sidebar ${isOpen ? 'open' : ''}`}>
  114.  
  115.         {/* <div style={{ display: 'flex', justifyContent: 'space-between', height: '56px', }}></div> */}
  116.         <div style={{ display: 'flex', justifyContent: 'space-between' ,height:'56px' ,width:'292px',padding:'20px 0 24px 0'}}>
  117.  
  118.           <div style={{ fontWeight: 600, fontSize: '20px', lineHeight:'28px', color:'#323130'}}>
  119.             {assetId?'Edit Additional Business Objective':'Add Additional Business Objective'}</div>
  120.           <div style={{ lineHeight:'32px'}}>
  121.             <Icon iconName="ChromeClose" className="close-icon" onClick={onClose} />
  122.           </div>
  123.         </div>
  124.          
  125.           <div  style={{width:'292px',padding:'20px 0 24px 0'}}>  
  126.           <Stack tokens={formTokens}>
  127.       <TextField
  128.         label="Business Objectives*"
  129.         placeholder="Enter Business Objectives"
  130.         value={formState.businessObjectives}
  131.         onChange={(e, newValue) => handleInputChange('businessObjectives', newValue)}
  132.       />
  133.       <Dropdown
  134.         label="Fiscal Year*"
  135.         selectedKey={formState.fiscalYear ? formState.fiscalYear.key : undefined}
  136.         onChange={(event, item) => handleInputChange('fiscalYear', item)}
  137.         placeholder="Select Fiscal Year"
  138.         options={objectiveOptions.fiscalYearOptions}
  139.       /><Dropdown
  140.       label="Owner"
  141.       selectedKey={formState.owner ? formState.owner.key : undefined}
  142.       onChange={(event, item) => handleInputChange('owner', item)}
  143.       placeholder="Select Owner"
  144.       options={objectiveOptions.ownerOptions}
  145.     />
  146.     <TextField
  147.       label="KPI"
  148.       placeholder="Enter KPI"
  149.       value={formState.kpi}
  150.       onChange={(e, newValue) => handleInputChange('kpi', newValue)}
  151.     />
  152.     <Dropdown
  153.       label="CSA*"
  154.       selectedKey={formState.csa ? formState.csa.key : undefined}
  155.       onChange={(event, item) => handleInputChange('csa', item)}
  156.       placeholder="Select CSA"
  157.       options={objectiveOptions.csaOptions}
  158.     />
  159.     <Dropdown
  160.       label="Industry"
  161.       selectedKey={formState.industry ? formState.industry.key : undefined}
  162.       onChange={(event, item) => handleInputChange('industry', item)}
  163.       placeholder="Select Industry"
  164.       options={objectiveOptions.industryOptions}
  165.     />
  166.     <Dropdown
  167.       label="GEO/OU"
  168.       selectedKey={formState.geoOu ? formState.geoOu.key : undefined}
  169.       onChange={(event, item) => handleInputChange('geoOu', item)}
  170.       placeholder="Select GEO/OU"
  171.       options={objectiveOptions.geoOuOptions}
  172.     />
  173.     <Dropdown
  174.       label="Segment"
  175.       selectedKey={formState.segment ? formState.segment.key : undefined}
  176.       onChange={(event, item) => handleInputChange('segment', item)}
  177.       placeholder="Select Segment"
  178.       options={objectiveOptions.segmentOptions}
  179.     />
  180.     {/* <Stack horizontal tokens={buttonStackTokens}>
  181.       <PrimaryButton text="Save" onClick={handleSubmit} allowDisabledFocus />
  182.       <DefaultButton text="Cancel" allowDisabledFocus />
  183.     </Stack> */}
  184.   </Stack>
  185.     </div>
  186.     <div  className="divider" />
  187.  
  188.     <div className='attachments'> Attachments</div>
  189.           <div className='info'>
  190.            <img src={info}  style={{height:'12px',width:'12px',paddingRight:'2px'}}/>
  191.          
  192.  
  193.             <div className='max-size-text'>Maximum size allowed for each file is 100 MB</div>
  194.           </div>
  195.          
  196.           <FileUpload setSelectedFiles={setSelectedFiles} selectedFiles={selectedFiles} />
  197.           <div style={{ display: 'flex', gap: 10, alignItems: 'center',marginTop:'24px' ,width:'242px'}}>
  198.  
  199.             <PrimaryButton onClick={() =>{} }>
  200.                {assetId?'Update':'Save'}
  201.             </PrimaryButton>
  202.               <DefaultButton
  203.                  onClick={onClose}>
  204.                            Cancel
  205.               </DefaultButton>
  206.           </div>
  207.  
  208.         </div>
  209.    
  210.     </>
  211.   );
  212.  
  213. export default CreateBusinessObjective;
  214.  
Tags: ui
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement