unioil-loyalty-rn-app/app/components/api/file.manager.js

30 lines
1.4 KiB
JavaScript

import React from 'react'
import EP from './endpoints';
import RNFetchBlob from 'rn-fetch-blob'
export default async function API(endpoint, method, headers, params, body, onSuccess, onError) {
RNFetchBlob.fetch(method, endpoint.includes(":") ? endpoint : EP[endpoint], {
Authorization : headers.Authorization,
'Content-Type' : 'multipart/form-data',
}, [
// { name : 'file', filename : 'photo.png', type: body.image.type, data: RNFetchBlob.wrap(decodeURIComponent(body.image.uri.replace("file:///", "")))},
{ name : 'photo', filename : body.image.name, type: body.image.type, data: RNFetchBlob.wrap(body.image.uri)},
{ name : 'firstname', data : body.firstname},
{ name : 'middlename', data : body.middlename},
{ name : 'lastname', data : body.lastname},
{ name : 'birthdate', data : body.birthdate},
{ name : 'mobile', data : body.mobile},
{ name : 'email', data : body.email},
{ name : 'address', data : body.address},
// { name : 'city', data : body.city},
{ name : 'vo_code', data : body.vo_code},
{ name : 'fueltype_code', data : body.fueltype_code},
{ name : 'civilstatus_code', data : body.civilstatus_code},
{ name : 'gender_code', data : body.gender_code},
{ name : 'is_deleted', data : body.is_deleted}
]).then((resp) => {
onSuccess(resp.json())
}).catch((err) => {
onError(err)
})
}