Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

async await doesnt help me with the popup alert after i get the response

  • I am new to react.
  • right now when I save an item from form fields I am able to save the data.
  • but the thing is first time the snack bar doesnt open up.
  • but the second time the snackbar opens up which says the the item is saved.
  • I tried to fix the issue with async await but still not working.
  • I also tried by putting in componentDidMount but still not helping me.
  • savesports is the method where I am trying to save the data.
  • this is where my snack bar opens up this.setState({ snackBarOpen: true });
  • can you guys tell me how to fix it so that in future I will fix it myself.
  • providing my code snippet below.
 < div className = { classes.sportsEditTabContentFooter } >

  {/*<div>sports Status</div>*/ }
  < div >
  <Button onClick={this.props.closeDrawer}>
    Cancel
                                </Button>
  <Button variant="outlined" onClick={this.savesports} className={classes.sportsFooterButton}>
    Save sports
                                </Button>
                            </div >
                        </div >
  savesports = async () => {
    console.log("savesports post---->");
    console.log(this.state.sports);
    let sports = this.state.sports;
    sports.sportsInsertUserRACF = 'DMT';
    sports.sportsUpdateDateTime = '2017-03-09';
    sports.sportsUpdateUserRACF = 'DMT';
    sports.sportsInsertDate = '2015-11-05';
    let snackBarMessage = this.state.sports.sportsCode;

    let samplesports = { "primaryFeeScheduleReimb": 100, "customNegotiatedPrimaryFeeSchedule": "Y", "customNegotiatedSecondaryFeeSchedule": "Y", "advancedImagingServices": "Y", "denyClinicalPath": "Y", "sportsTerminationDate": "2018-12-12", "sportsEffectiveDate": "2018-12-12", "sportsCode": "1212002", "primaryFeeScheduleID": "1", "secondaryFeeScheduleReimb": 100, "secondaryFeeScheduleID": "2", "locality": "03", "medicareYear": "2000", "percentOfMedicare": "100", "rvuCF": "1", "anesthesiaCF": "1", "labPercent": "1", "obCodeRate": "1", "percentOfPBF": "1", "serviceBlocks": "Digital Mammography", "drugs": "MEDICARE", "alpoFlag": "Y", "anesthesiaCap": "Y", "anesthesiaPPM": "Y", "primaryCarePhysician": "Y", "physicalTherapy": "Y", "pos": "M", "floridaBlueNumber": "m", "sportsIncludesCapitation": "Y", "capitationVendorTaxID": "m", "ipaID": "m", "sequestrationReduction": "Y", "network": "HMO", "role": "AMB", "specialty": "INTERNAL MEDICINE", "sportsStatus": "ACTIVE", "sportsParticipation": "Par", "sportsPanelID": "m", "priceRuleDescription": "m", "priceRule": "m", "sportsComments": "m", "primaryFeeScheduleDescription": "m", "secondaryFeeScheduleDescription": "m", "sportsInsertUserRACF": "DMT", "sportsUpdateDateTime": "2017-03-09", "sportsUpdateUserRACF": "DMT", "sportsInsertDate": "2015-11-05" };

    samplesports.sportsCode = this.state.sports.sportsCode;

    await axios({
      method: 'post',
      url: 'http://domain.player.com/sports',
      // data: samplesports,
      data: sports,

      config: { headers: { 'Content-Type': 'application/json' } }
    })

      .then(resp => {
        snackBarMessage = `${snackBarMessage} saved successfully`;
        this.setState({ snackBarMessage: snackBarMessage });
        // debugger;
        console.log("snack suce--->", resp);
        this.info = resp;
        //this.info = await resp;
        //this.setState({ right: false });



        debugger;
        this.setState({ snackBarOpen: true });

        this.props.fetchsportsDatafromURL(this.props.primaryParameters);
        setTimeout(() => {
          this.setState({ snackBarOpen: false });
          //this.props.closeDrawer();
        }, 6000)
      })
      .catch(resp => {
        //  debugger;
        console.log("snack error--->", resp);
        this.info = resp;
        //this.setState({ right: false });
        // this.props.closeDrawer();
        //  debugger;
        this.setState({ snackBarOpen: true });

        snackBarMessage = `${snackBarMessage} not saved`;
        //snackBarMessage = 'sports not saved';
        this.setState({ snackBarMessage: snackBarMessage });
        setTimeout(() => {
          this.setState({ snackBarOpen: false });
          this.props.closeDrawer();
        }, 6000)
      })

  };

Comments