diy-template-components 0.1.21 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.es.js CHANGED
@@ -7489,7 +7489,7 @@ const formPageMock = {
7489
7489
  subTitle: 'Sed ut perspiciatis unde omnis iste natus error',
7490
7490
  questions: [{
7491
7491
  _id: '22',
7492
- text: 'fdsafds',
7492
+ text: 'Question 0',
7493
7493
  type: 'SA',
7494
7494
  options: [{
7495
7495
  value: ''
@@ -7498,31 +7498,19 @@ const formPageMock = {
7498
7498
  order: 1
7499
7499
  }, {
7500
7500
  _id: '23',
7501
- text: 'fasdfdsaffdsafds',
7502
- type: 'MC',
7501
+ text: 'Question 1',
7502
+ type: 'SA',
7503
7503
  options: [{
7504
- value: 'fadsfdsf'
7505
- }, {
7506
- value: 'fdsafdsaf'
7507
- }, {
7508
- value: 'fsadfd'
7509
- }, {
7510
- value: 'fadsf'
7504
+ value: ''
7511
7505
  }],
7512
7506
  isRequired: false,
7513
7507
  order: 1
7514
7508
  }, {
7515
7509
  _id: '24',
7516
- text: 'ewaofdsfkds',
7517
- type: 'SC',
7510
+ text: 'Question 2',
7511
+ type: 'SA',
7518
7512
  options: [{
7519
- value: 'fasdfdsf'
7520
- }, {
7521
- value: 'fasdfdasf'
7522
- }, {
7523
- value: 'fdsafsdf'
7524
- }, {
7525
- value: 'fdsafds'
7513
+ value: ''
7526
7514
  }],
7527
7515
  isRequired: false,
7528
7516
  order: 1
@@ -7535,6 +7523,7 @@ const FormPage = ({
7535
7523
  }) => {
7536
7524
  const [formData, setFormData] = useState({});
7537
7525
  const classes = useFormPageStyles();
7526
+ const [formSubmitted, setformSubmitted] = useState(false);
7538
7527
  const metadata = sectionData?.components?.[0]?.metadata || formPageMock;
7539
7528
  const {
7540
7529
  _id,
@@ -7561,8 +7550,22 @@ const FormPage = ({
7561
7550
  };
7562
7551
  postApiCallForm(baseURLs, data, extraProps);
7563
7552
  setFormData({});
7553
+ setformSubmitted(!formSubmitted);
7564
7554
  };
7565
7555
 
7556
+ useEffect(() => {
7557
+ //add all questions to formData
7558
+ let formData = {};
7559
+ metadata.questions.forEach(question => {
7560
+ formData[question._id] = {
7561
+ questionName: question.text,
7562
+ questionType: question.type,
7563
+ solutionArray: []
7564
+ };
7565
+ });
7566
+ setFormData(formData);
7567
+ }, [metadata, formSubmitted]);
7568
+
7566
7569
  const handleOnClick = (e, item, option) => {
7567
7570
  // if the checkbox is checked
7568
7571
  if (!e.target.checked) {
@@ -7636,6 +7639,7 @@ const FormPage = ({
7636
7639
  onChange: e => {
7637
7640
  setFormData({ ...formData,
7638
7641
  [item._id]: {
7642
+ index,
7639
7643
  questionName: item.text,
7640
7644
  solutionArray: [e.target.value],
7641
7645
  questionType: 'SA'