export const PENJADWALAN_CREATE_REQUEST = "PENJADWALAN_CREATE_REQUEST";
export const PENJADWALAN_CREATE_SUCCESS = "PENJADWALAN_CREATE_SUCCESS";
export const PENJADWALAN_CREATE_FAIL = "PENJADWALAN_CREATE_FAIL";
export const PENJADWALAN_CREATE_RESET = "PENJADWALAN_CREATE_RESET";

export const createPenjadwalan =
	({ number, ptId }, penjadwalanData) =>
	async (dispatch) => {
		try {
			dispatch({
				type: PENJADWALAN_CREATE_REQUEST,
			});

			const myHeaders = new Headers();
			myHeaders.append("Content-Type", "application/json");
			const res = await fetch(`http://localhost:5000/pelaporan/jadwal/add?number=${number}&ptId=${ptId}`, {
				method: "POST",
				body: penjadwalanData,
				headers: myHeaders,
			});
			const data = await res.json();

			dispatch({
				type: PENJADWALAN_CREATE_SUCCESS,
				payload: data,
			});
		} catch (error) {
			dispatch({
				type: PENJADWALAN_CREATE_FAIL,
				payload: error.response && error.response.data.message ? error.response.data.message : error.message,
			});
		}
	};
