Untitled

 avatar
user_1697073
plain_text
7 months ago
4.5 kB
2
Indexable
Never
 onPressSaveButton = async () => {
    console.log("this.state.media_urlthis.state.media_urlthis.state.media_url", this.state.media_urlInput)
    // this.setState({ loading: true })
    const token = await getStorageData('USER_TOKEN')
    let formData = new FormData()

    // const _userId = this.props.navigation.state.params.userID
    //   ? this.props.navigation.state.params.userID
    //   : ''
    //console.log("datasoftheea",formData)
    const _userId = await getStorageData('USER_ID')

    this.setState({ loader: true })  
    // console.log('user id in edit profile api body>>>>', _userId)


    //console.log('iamge in edit api >>>>>', name, uri, formData)  

    if (this.state.songName != this.state.songNameInput) {
      formData.append('account[song_name]', this.state.songNameInput)
    }  
    if (this.state.selectedSongTrack_id != this.state.selectedSongTrack_idInput) {
      formData.append('account[spotify_track_id]', this.state.selectedSongTrack_id)
    }  

    if (this.state.artistName != this.state.artistNameInput) {
      formData.append('account[artist_name]', this.state.artistNameInput)
    }  

    if (this.state.imageUrl != this.state.imageUrlInput) {
      formData.append('account[image_url]', this.state.imageUrlInput)
    }   

    if (this.state.fullName != this.state.fullNameInput) {
      formData.append('account[fullname]', this.state.fullNameInput)
    }   

    if (this.state.userName != this.state.userNameInput) {
      formData.append('account[user_name]', this.state.userNameInput)
    }   

    if (this.state.bio != this.state.bioInput) {
      formData.append('account[bio]', this.state.bio)
    }   

    if (this.state.media_url != this.state.mediaUrlInput) {
      formData.append('account[media_url]', this.state.media_urlInput)
    }  
    formData.append('account[user_type]', 'user')
    //console.log('body data of edit this.state.media_urlthis.state.media_urlthis.state.media_urlthis.state.media_url api>>>>>', formData)
    
    if (
      !this.state.coverImage?.includes('https') &&
      this.state.coverImage?.length === 0
    ) {
    } else if (
      !this.state.coverImage?.includes('https') &&
      this.state.coverImage?.length != 0
    )     
    {
      const dateData = new Date().getTime() + '.' + 'jpg'
      let name = this.state.coverImageData?.fileName
        ? this.state.coverImageData?.fileName
        : dateData
      let uri = this.state.coverImageData?.path
      let type = this.state.coverImageData?.type
        ? this.state.coverImageData?.type
        : 'image/jpg'

      if (this.state.coverImage?.length !== 0) {
        formData.append('account[cover_pic]', {
          name,
          uri,
          type,
        })
      }
    }    

    if (
      !this.state.profileImage?.includes('https') &&
      this.state.profileImage?.length == 0
    ) {
    } else if (
      !this.state.profileImage?.includes('https') &&
      this.state.profileImage?.length != 0
    ) {
      const dateData = new Date().getTime() + '.' + 'jpg'
      let name = this.state.profileImageData?.fileName
        ? this.state.profileImageData?.fileName
        : dateData
      let uri = this.state.profileImageData?.path
      let type = this.state.profileImageData?.type
        ? this.state.profileImageData?.type
        : 'image/jpg'

      if (this.state.profileImage?.length !== 0) {
        formData.append('account[profile_pic]', {
          name,
          uri,
          type,
        })
      }
    }   


    const header = {
      'Content-Type': 'multipart/form-data',
      token: token,
    }

    const requestMessage = new Message(
      getName(MessageEnum.RestAPIRequestMessage),
    )

    this.editProfileApiCallId = requestMessage.messageId

    requestMessage.addData(
      getName(MessageEnum.RestAPIResponceEndPointMessage),
      configJSON.editProfileApiEndPoint,
      // configJSON.editProfileApiEndPoint + `/${_userId}`,
    )

    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestHeaderMessage),
      JSON.stringify(header),
    )

    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestBodyMessage),
      formData,
    )

    requestMessage.addData(
      getName(MessageEnum.RestAPIRequestMethodMessage),
      configJSON.createAPiPutMethod,
    )

    // console.log(
    //   '@@@ Request of edit profile page >>===========>',
    //   requestMessage,
    //   this.editProfileApiCallId,
    // )

    runEngine.sendMessage(requestMessage.id, requestMessage)
    return true
  }