Created
March 15, 2019 22:15
-
-
Save jordanhudgens/7e41c5254b86937daff5451247ec7178 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// store/modules/hours.js | |
import axios from "axios"; | |
const state = { | |
selectedHourOfOperation: null, | |
activeHourOfOperationModal: false | |
}; | |
const getters = { | |
currentHourOfOperation: state => { | |
return state.selectedHourOfOperation; | |
}, | |
hourOfOperationModalIsActive: state => { | |
return state.activeHourOfOperationModal; | |
} | |
}; | |
const mutations = { | |
TOGGLE_ACTIVE_HOUR_OF_OPERATION_MODAL: state => { | |
if (state.activeHourOfOperationModal) { | |
state.activeHourOfOperationModal = false; | |
} else { | |
state.activeHourOfOperationModal = true; | |
} | |
}, | |
SET_HOURS_OF_OPERATION_FOR_MODAL: (state, hourOfOperation) => { | |
state.selectedHourOfOperation = hourOfOperation; | |
}, | |
CLEAR_HOURS_OF_OPERATION_FOR_MODAL: state => { | |
state.selectedHourOfOperation = null; | |
} | |
}; | |
const actions = { | |
updateHoursOfOperation: (context, payload) => { | |
axios | |
.patch( | |
`https://api.toastability.com/hours_of_operations/${payload.dayId}`, | |
{ | |
hours_of_operation: { | |
location_id: payload.locationId, | |
[payload.openOrClose]: payload.hourValue | |
} | |
}, | |
{ | |
transformRequest: [response => JSON.stringify(response)], | |
headers: { | |
Accept: "application/json", | |
"Content-Type": "application/json" | |
}, | |
withCredentials: true | |
} | |
) | |
.then(response => { | |
context.commit( | |
"UPDATE_HOURS_OF_OPERATION", | |
response.data.hours_of_operation, | |
{ | |
root: true | |
} | |
); | |
}) | |
.catch(error => { | |
console.log("errorrr"); | |
}); | |
} | |
}; | |
export default { | |
state, | |
getters, | |
mutations, | |
actions | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment