70 lines
2.0 KiB
JavaScript
70 lines
2.0 KiB
JavaScript
import { TYPE_APP_WHATS_HOT, TYPE_APP_PROMOS } from '../types';
|
|
import REQUEST from '../../components/api/';
|
|
|
|
const dispatchAction = (actionType, data) => {
|
|
return ({
|
|
type: actionType,
|
|
value: data
|
|
})
|
|
}
|
|
|
|
const parse_data = (res) => {
|
|
let wh = []
|
|
for(var x=0;x<res.data.length;x++){
|
|
if(res.data[x].image.includes("mobiletestbuckethttps")){
|
|
wh.push(res.data[x].image.replace("https://s3-ap-southeast-1.amazonaws.com/unioil.mobiletestbucket", ""))
|
|
}else{
|
|
wh.push(res.data[x].image)
|
|
}
|
|
}
|
|
return wh
|
|
}
|
|
|
|
const fetchWhatshot = (dispatch, token, lcard_uuid) => {
|
|
return new Promise(function(resolve, reject) {
|
|
REQUEST("whats_hot", "get", token, lcard_uuid, {},
|
|
(success) => {
|
|
const data = (success.status == 1 && success.data.length > 0) ? parse_data(success) : []
|
|
dispatch(dispatchAction(TYPE_APP_WHATS_HOT, data))
|
|
resolve(data)
|
|
},
|
|
(error) => reject(error))
|
|
})
|
|
}
|
|
|
|
const fetchPromos = (dispatch, token, lcard_uuid) => {
|
|
return new Promise(function(resolve, reject) {
|
|
REQUEST("new_promos", "get", token, lcard_uuid, {},
|
|
(success) => {
|
|
const data = (success.status == 1 && success.data.length > 0) ? success.data : []
|
|
dispatch(dispatchAction(TYPE_APP_PROMOS, data))
|
|
resolve(data)
|
|
},
|
|
(error) => reject(error))
|
|
})
|
|
}
|
|
|
|
export const saveWhatshot = (data) => {
|
|
return function(dispatch) {
|
|
return fetchWhatshot(dispatch, { Authorization: data.token }, `lcard_uuid=${data.lcard_uuid}`)
|
|
}
|
|
}
|
|
|
|
export const savePromos = (data) => {
|
|
return function(dispatch) {
|
|
return fetchPromos(dispatch, { Authorization: data.token }, `lcard_uuid=${data.lcard_uuid}`)
|
|
}
|
|
}
|
|
|
|
export const saveGuestWhatshot = () => {
|
|
return function(dispatch) {
|
|
return fetchWhatshot(dispatch, {}, {})
|
|
}
|
|
}
|
|
|
|
export const saveGuestPromos = () => {
|
|
return function(dispatch) {
|
|
return fetchPromos(dispatch, {}, {})
|
|
}
|
|
}
|