Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier changes #1157

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"vueIndentScriptAndStyle": false,
"proseWrap": "preserve",
"insertPragma": false,
"printWidth": 80,
"printWidth": 120,
"requirePragma": false,
"tabWidth": 2,
"useTabs": false,
Expand Down
19 changes: 3 additions & 16 deletions src/actionCreators/commonActionCreator.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import { normalize } from 'normalizr';
import {
axios,
createConfigWithHeader,
saveReferencesInLocalStorage,
} from '../utils';
import { axios, createConfigWithHeader, saveReferencesInLocalStorage } from '../utils';
import * as API from '../constants/api';
import {
storeUsers,
storeReferences,
storeZones,
request,
success,
error,
} from '../actions';
import { storeUsers, storeReferences, storeZones, request, success, error } from '../actions';
import * as schema from './schema';
import { GET_USERS, GET_ZONES } from '../constants/reducerTypes';

Expand Down Expand Up @@ -58,9 +47,7 @@ export const fetchReferences = () => (dispatch, getState) => {
if (err?.status === 401) {
// Request was unauthorized, user probably hasn't logged in yet.
} else {
console.warn(
`Error fetching references, '${err}'. Falling back to locally stored references`,
);
console.warn(`Error fetching references, '${err}'. Falling back to locally stored references`);
}
});
};
Expand Down
225 changes: 107 additions & 118 deletions src/actionCreators/grazingScheduleActionCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,135 +5,124 @@ import * as reducerTypes from '../constants/reducerTypes';
import * as API from '../constants/api';
import { axios, createConfigWithHeader } from '../utils';

export const createRUPGrazingScheduleEntry =
(planId, grazingScheduleId, entry) => (dispatch, getState) => {
return axios
.post(
API.CREATE_RUP_GRAZING_SCHEDULE_ENTRY(planId, grazingScheduleId),
{ ...entry, plan_id: planId },
createConfigWithHeader(getState),
)
.then(
(response) => {
const newEntry = response.data;
return newEntry;
},
(err) => {
throw err;
},
);
export const createRUPGrazingScheduleEntry = (planId, grazingScheduleId, entry) => (dispatch, getState) => {
return axios
.post(
API.CREATE_RUP_GRAZING_SCHEDULE_ENTRY(planId, grazingScheduleId),
{ ...entry, plan_id: planId },
createConfigWithHeader(getState),
)
.then(
(response) => {
const newEntry = response.data;
return newEntry;
},
(err) => {
throw err;
},
);
};

export const createRUPGrazingSchedule = (planId, schedule) => (dispatch, getState) => {
const makeRequest = async () => {
const { data: newSchedule } = await axios.post(
API.CREATE_RUP_GRAZING_SCHEDULE(planId),
{ ...schedule, plan_id: planId },
createConfigWithHeader(getState),
);
// const newGses = await Promise.all(schedule.grazingScheduleEntries
// .map(gse => dispatch(createRUPGrazingScheduleEntry(planId, newSchedule.id, gse))));

return {
...newSchedule,
// grazingScheduleEntries: newGses,
};
};
return makeRequest();
};

export const createRUPGrazingSchedule =
(planId, schedule) => (dispatch, getState) => {
const makeRequest = async () => {
const { data: newSchedule } = await axios.post(
const createRUPGrazingScheduleAndEntries = (planId, schedule) => (dispatch, getState) => {
dispatch(request(reducerTypes.CREATE_GRAZING_SCHEDULE_AND_ENTRIES));
const makeRequest = async () => {
try {
const { ...grazingSchedule } = schedule;
const { data } = await axios.post(
API.CREATE_RUP_GRAZING_SCHEDULE(planId),
{ ...schedule, plan_id: planId },
{ ...grazingSchedule, plan_id: planId },
createConfigWithHeader(getState),
);
// const newGses = await Promise.all(schedule.grazingScheduleEntries
// .map(gse => dispatch(createRUPGrazingScheduleEntry(planId, newSchedule.id, gse))));

return {
...newSchedule,
// grazingScheduleEntries: newGses,
};
};
return makeRequest();
dispatch(success(reducerTypes.CREATE_GRAZING_SCHEDULE_AND_ENTRIES, data));
return data;
} catch (err) {
dispatch(error(reducerTypes.CREATE_GRAZING_SCHEDULE_AND_ENTRIES, err));
dispatch(toastErrorMessage(err));
throw err;
}
};
return makeRequest();
};

const createRUPGrazingScheduleAndEntries =
(planId, schedule) => (dispatch, getState) => {
dispatch(request(reducerTypes.CREATE_GRAZING_SCHEDULE_AND_ENTRIES));
const makeRequest = async () => {
try {
const { ...grazingSchedule } = schedule;
const { data } = await axios.post(
API.CREATE_RUP_GRAZING_SCHEDULE(planId),
{ ...grazingSchedule, plan_id: planId },
createConfigWithHeader(getState),
);
dispatch(
success(reducerTypes.CREATE_GRAZING_SCHEDULE_AND_ENTRIES, data),
);
return data;
} catch (err) {
dispatch(error(reducerTypes.CREATE_GRAZING_SCHEDULE_AND_ENTRIES, err));
dispatch(toastErrorMessage(err));
throw err;
}
};
return makeRequest();
const updateRUPGrazingScheduleAndEntries = (planId, schedule) => (dispatch, getState) => {
dispatch(request(reducerTypes.UPDATE_GRAZING_SCHEDULE_AND_ENTRIES));
const makeRequest = async () => {
try {
const { data } = await axios.put(
API.UPDATE_RUP_GRAZING_SCHEDULE(planId, schedule.id),
{ ...schedule },
createConfigWithHeader(getState),
);
dispatch(success(reducerTypes.UPDATE_GRAZING_SCHEDULE_AND_ENTRIES, data));
return data;
} catch (err) {
dispatch(error(reducerTypes.UPDATE_GRAZING_SCHEDULE_AND_ENTRIES, err));
dispatch(toastErrorMessage(err));
throw err;
}
};
return makeRequest();
};

const updateRUPGrazingScheduleAndEntries =
(planId, schedule) => (dispatch, getState) => {
dispatch(request(reducerTypes.UPDATE_GRAZING_SCHEDULE_AND_ENTRIES));
const makeRequest = async () => {
try {
const { data } = await axios.put(
API.UPDATE_RUP_GRAZING_SCHEDULE(planId, schedule.id),
{ ...schedule },
createConfigWithHeader(getState),
);
dispatch(
success(reducerTypes.UPDATE_GRAZING_SCHEDULE_AND_ENTRIES, data),
);
return data;
} catch (err) {
dispatch(error(reducerTypes.UPDATE_GRAZING_SCHEDULE_AND_ENTRIES, err));
dispatch(toastErrorMessage(err));
throw err;
}
};
return makeRequest();
};
export const createOrUpdateRUPGrazingSchedule = (planId, schedule) => (dispatch) => {
if (uuid.isUUID(schedule.id)) {
return dispatch(createRUPGrazingScheduleAndEntries(planId, schedule));
}
return dispatch(updateRUPGrazingScheduleAndEntries(planId, schedule));
};

export const createOrUpdateRUPGrazingSchedule =
(planId, schedule) => (dispatch) => {
if (uuid.isUUID(schedule.id)) {
return dispatch(createRUPGrazingScheduleAndEntries(planId, schedule));
export const deleteRUPGrazingSchedule = (planId, scheduleId) => (dispatch, getState) => {
dispatch(request(reducerTypes.DELETE_GRAZING_SCHEUDLE));
const makeRequest = async () => {
try {
const { data } = await axios.delete(
API.DELETE_RUP_GRAZING_SCHEDULE(planId, scheduleId),
createConfigWithHeader(getState),
);
dispatch(success(reducerTypes.DELETE_GRAZING_SCHEUDLE, data));
return data;
} catch (err) {
dispatch(error(reducerTypes.DELETE_GRAZING_SCHEUDLE, err));
dispatch(toastErrorMessage(err));
throw err;
}
return dispatch(updateRUPGrazingScheduleAndEntries(planId, schedule));
};

export const deleteRUPGrazingSchedule =
(planId, scheduleId) => (dispatch, getState) => {
dispatch(request(reducerTypes.DELETE_GRAZING_SCHEUDLE));
const makeRequest = async () => {
try {
const { data } = await axios.delete(
API.DELETE_RUP_GRAZING_SCHEDULE(planId, scheduleId),
createConfigWithHeader(getState),
);
dispatch(success(reducerTypes.DELETE_GRAZING_SCHEUDLE, data));
return data;
} catch (err) {
dispatch(error(reducerTypes.DELETE_GRAZING_SCHEUDLE, err));
dispatch(toastErrorMessage(err));
throw err;
}
};
return makeRequest();
};
return makeRequest();
};

export const deleteRUPGrazingScheduleEntry =
(planId, scheduleId, entryId) => (dispatch, getState) => {
dispatch(request(reducerTypes.DELETE_GRAZING_SCHEUDLE_ENTRY));
const makeRequest = async () => {
try {
const { data } = await axios.delete(
API.DELETE_RUP_GRAZING_SCHEDULE_ENTRY(planId, scheduleId, entryId),
createConfigWithHeader(getState),
);
dispatch(success(reducerTypes.DELETE_GRAZING_SCHEUDLE_ENTRY, data));
return data;
} catch (err) {
dispatch(error(reducerTypes.DELETE_GRAZING_SCHEUDLE_ENTRY, err));
dispatch(toastErrorMessage(err));
throw err;
}
};
return makeRequest();
export const deleteRUPGrazingScheduleEntry = (planId, scheduleId, entryId) => (dispatch, getState) => {
dispatch(request(reducerTypes.DELETE_GRAZING_SCHEUDLE_ENTRY));
const makeRequest = async () => {
try {
const { data } = await axios.delete(
API.DELETE_RUP_GRAZING_SCHEDULE_ENTRY(planId, scheduleId, entryId),
createConfigWithHeader(getState),
);
dispatch(success(reducerTypes.DELETE_GRAZING_SCHEUDLE_ENTRY, data));
return data;
} catch (err) {
dispatch(error(reducerTypes.DELETE_GRAZING_SCHEUDLE_ENTRY, err));
dispatch(toastErrorMessage(err));
throw err;
}
};
return makeRequest();
};
Loading
Loading