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

[TM-5572] Bidding Tool Integration (Edit) #2856

Merged
merged 14 commits into from
Jun 12, 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
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ const BiddingToolCard = (props) => {
const resultIsLoading = (isCreate ?
useSelector(state => state.biddingToolCreateDataLoading) :
useSelector(state => state.biddingToolFetchDataLoading)) || false;
const deleteErrored = useSelector(state => state.biddingToolDeleteErrored);
const createErrored = useSelector(state => state.biddingToolCreateErrored);

const locations = result?.locations || [];
const statuses = result?.statuses || [];
Expand Down Expand Up @@ -127,7 +125,37 @@ const BiddingToolCard = (props) => {
const [values, setValues] = useState(initialValues);
useEffect(() => {
if (editMode) {
setValues(initialValues);
setValues({
location: result?.location,
status: result?.status,
tod: result?.tod,
unaccompanied_status: result?.unaccompanied_status,
housing: result?.housing,
quarters: result?.quarters,
efm_issues: result?.efm_issues,

snd: result?.snd ?? 'N',
hds: result?.hds ?? 'N',
apo_fpo_dpo: result?.apo_fpo_dpo ?? 'N',
consumable_allowance: result?.consumable_allowance ?? 'N',
fm_fp: result?.fm_fp ?? 'N',
inside_efm_employment: result?.inside_efm_employment ?? 'N',
outside_efm_employment: result?.outside_efm_employment ?? 'N',

cola: result?.cola,
differential_rate: result?.differential_rate,
danger_pay: result?.danger_pay,
climate_zone: result?.climate_zone,

rr_point: result?.rr_point ?? '',
medical: result?.medical ?? '',
remarks: result?.remarks ?? '',
quarters_remark: result?.quarters_remark ?? '',
special_ship_allowance: result?.special_ship_allowance ?? '',
school_year: result?.school_year ?? '',
grade_education: result?.grade_education ?? '',
efm_employment: result?.efm_employment ?? '',
});
}
}, [editMode]);

Expand All @@ -139,11 +167,11 @@ const BiddingToolCard = (props) => {
{ 'R & R Point': result?.rr_point || 'None Listed' },
{ 'COLA': result?.cola?.toString() || 'None Listed' },
{ 'Differential Rate': result?.differential_rate?.toString() || 'None Listed' },
{ 'Consumable Allowance': result?.consumable_allowance ? 'Yes' : 'No' },
{ 'APO/FPO/DPO': result?.apo_fpo_dpo ? 'Yes' : 'No' },
{ 'Consumable Allowance': result?.consumable_allowance === 'Y' ? 'Yes' : 'No' },
{ 'APO/FPO/DPO': result?.apo_fpo_dpo === 'Y' ? 'Yes' : 'No' },
{ 'Danger Pay': result?.danger_pay?.toString() || 'None Listed' },
{ 'SND': result?.snd ? 'Yes' : 'No' },
{ 'HDS': result?.hds ? 'Yes' : 'No' },
{ 'SND': result?.snd === 'Y' ? 'Yes' : 'No' },
{ 'HDS': result?.hds === 'Y' ? 'Yes' : 'No' },
{ 'Unaccompanied Status': unaccompaniedStatuses.find(o => o.code === result?.unaccompanied_status)?.description || 'None Listed' },
{ 'Housing Type': housingTypes.find(o => o.code === result?.housing_type)?.description || 'None Listed' },
{ 'Quarters': quartersTypes.find(o => o.code === result?.quarters_type)?.description || 'None Listed' },
Expand Down Expand Up @@ -239,15 +267,15 @@ const BiddingToolCard = (props) => {
const onSubmit = () => {
if (isCreate) {
dispatch(biddingToolCreate(values));
if (!createErrored) {
history.push(`${rootLocation()}/${values.location}`);
}
} else {
dispatch(biddingToolEdit({
...values,
updater_id: result?.updater_id,
updated_date: result?.updated_date,
}));
dispatch(biddingToolEdit(
{
...values,
updater_id: result?.updater_id,
updated_date: result?.updated_date,
},
() => setEditMode(false),
));
}
};

Expand Down Expand Up @@ -282,15 +310,14 @@ const BiddingToolCard = (props) => {
};

const onDelete = () => {
dispatch(biddingToolDelete({
location: id,
updater_id: result?.updater_id,
updated_date: result?.updated_date,
}));
swal.close();
if (!deleteErrored) {
history.push(rootLocation());
}
dispatch(biddingToolDelete(
{
location: id,
updater_id: result?.updater_id,
updated_date: result?.updated_date,
},
() => swal.close(),
));
};
const showDeleteModal = () => {
swal({
Expand Down
180 changes: 54 additions & 126 deletions src/actions/biddingTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { CancelToken } from 'axios';
import { batch } from 'react-redux';
import api from '../api';
import { toastError, toastSuccess } from './toast';
import { history } from '../store';

let cancelBiddingTool;

Expand Down Expand Up @@ -120,103 +121,54 @@ export function biddingTools() {

// ================ BIDDING TOOL DELETE ================

export function biddingToolDeleteErrored(bool) {
return {
type: 'BIDDING_TOOL_DELETE_ERRORED',
hasErrored: bool,
};
}
export function biddingToolDeleteLoading(bool) {
return {
type: 'BIDDING_TOOL_DELETE_LOADING',
isLoading: bool,
};
}
export function biddingToolDeleteSuccess(results) {
return {
type: 'BIDDING_TOOL_DELETE_SUCCESS',
results,
};
}
export function biddingToolDelete(query) {
let cancelDelete;

export function biddingToolDelete(query, onSuccess) {
return (dispatch) => {
batch(() => {
dispatch(biddingToolDeleteLoading(true));
dispatch(biddingToolDeleteErrored(false));
});
api().delete('/fsbid/bidding_tool/', query)
.then(({ data }) => {
batch(() => {
dispatch(biddingToolDeleteErrored(false));
dispatch(biddingToolDeleteSuccess(data));
dispatch(toastSuccess(DELETE_BIDDING_TOOL_SUCCESS, DELETE_BIDDING_TOOL_SUCCESS_TITLE));
dispatch(biddingToolDeleteLoading(false));
});
if (cancelDelete) {
cancelDelete('cancel');
}

api().delete('/fsbid/bidding_tool/', query, {
cancelToken: new CancelToken((c) => { cancelDelete = c; }),
})
.then(() => {
dispatch(toastSuccess(DELETE_BIDDING_TOOL_SUCCESS, DELETE_BIDDING_TOOL_SUCCESS_TITLE));
history.push('/profile/biddingtool');
if (onSuccess) {
onSuccess();
}
})
.catch((err) => {
if (err?.message === 'cancel') {
batch(() => {
dispatch(biddingToolDeleteLoading(true));
dispatch(biddingToolDeleteErrored(false));
});
} else {
batch(() => {
dispatch(biddingToolDeleteErrored(true));
dispatch(toastError(DELETE_BIDDING_TOOL_ERROR, DELETE_BIDDING_TOOL_ERROR_TITLE));
dispatch(biddingToolDeleteLoading(false));
});
if (err?.message !== 'cancel') {
dispatch(toastError(DELETE_BIDDING_TOOL_ERROR, DELETE_BIDDING_TOOL_ERROR_TITLE));
}
});
};
}

// ================ BIDDING TOOL EDIT ================

export function biddingToolEditErrored(bool) {
return {
type: 'BIDDING_TOOL_EDIT_ERRORED',
hasErrored: bool,
};
}
export function biddingToolEditLoading(bool) {
return {
type: 'BIDDING_TOOL_EDIT_LOADING',
isLoading: bool,
};
}
export function biddingToolEditSuccess(results) {
return {
type: 'BIDDING_TOOL_EDIT_SUCCESS',
results,
};
}
export function biddingToolEdit(query) {
let cancelEdit;

export function biddingToolEdit(query, onSuccess) {
return (dispatch) => {
batch(() => {
dispatch(biddingToolEditLoading(true));
dispatch(biddingToolEditErrored(false));
});
api().put('/fsbid/bidding_tool/', query)
.then(({ data }) => {
batch(() => {
dispatch(biddingToolEditErrored(false));
dispatch(biddingToolEditSuccess(data));
dispatch(toastSuccess(EDIT_BIDDING_TOOL_SUCCESS, EDIT_BIDDING_TOOL_SUCCESS_TITLE));
dispatch(biddingToolEditLoading(false));
});
if (cancelEdit) {
cancelEdit('cancel');
}

api().put('/fsbid/bidding_tool/', query, {
cancelToken: new CancelToken((c) => { cancelEdit = c; }),
})
.then(() => {
dispatch(toastSuccess(EDIT_BIDDING_TOOL_SUCCESS, EDIT_BIDDING_TOOL_SUCCESS_TITLE));
if (onSuccess) {
onSuccess();
}
})
.catch((err) => {
if (err?.message === 'cancel') {
batch(() => {
dispatch(biddingToolEditLoading(true));
dispatch(biddingToolEditErrored(false));
});
} else {
batch(() => {
dispatch(biddingToolEditErrored(true));
dispatch(toastError(EDIT_BIDDING_TOOL_ERROR, EDIT_BIDDING_TOOL_ERROR_TITLE));
dispatch(biddingToolEditLoading(false));
});
if (err?.message !== 'cancel') {
dispatch(toastError(EDIT_BIDDING_TOOL_ERROR, EDIT_BIDDING_TOOL_ERROR_TITLE));
}
});
};
Expand All @@ -225,51 +177,27 @@ export function biddingToolEdit(query) {

// ================ BIDDING TOOL CREATE ================

export function biddingToolCreateErrored(bool) {
return {
type: 'BIDDING_TOOL_CREATE_ERRORED',
hasErrored: bool,
};
}
export function biddingToolCreateLoading(bool) {
return {
type: 'BIDDING_TOOL_CREATE_LOADING',
isLoading: bool,
};
}
export function biddingToolCreateSuccess(results) {
return {
type: 'BIDDING_TOOL_CREATE_SUCCESS',
results,
};
}
export function biddingToolCreate(query) {
let cancelCreate;

export function biddingToolCreate(query, onSuccess) {
return (dispatch) => {
batch(() => {
dispatch(biddingToolCreateLoading(true));
dispatch(biddingToolCreateErrored(false));
});
api().put('/fsbid/bidding_tool/', query)
.then(({ data }) => {
batch(() => {
dispatch(biddingToolCreateErrored(false));
dispatch(biddingToolCreateSuccess(data));
dispatch(toastSuccess(CREATE_BIDDING_TOOL_SUCCESS, CREATE_BIDDING_TOOL_SUCCESS_TITLE));
dispatch(biddingToolCreateLoading(false));
});
if (cancelCreate) {
cancelCreate('cancel');
}

api().post('/fsbid/bidding_tool/', query, {
cancelToken: new CancelToken((c) => { cancelCreate = c; }),
})
.then((response) => {
dispatch(toastSuccess(CREATE_BIDDING_TOOL_SUCCESS, CREATE_BIDDING_TOOL_SUCCESS_TITLE));
history.push(`/profile/biddingtool/${response?.O_LOCATION_CODE}`);
if (onSuccess) {
onSuccess();
}
})
.catch((err) => {
if (err?.message === 'cancel') {
batch(() => {
dispatch(biddingToolCreateLoading(true));
dispatch(biddingToolCreateErrored(false));
});
} else {
batch(() => {
dispatch(biddingToolCreateErrored(true));
dispatch(toastError(CREATE_BIDDING_TOOL_ERROR, CREATE_BIDDING_TOOL_ERROR_TITLE));
dispatch(biddingToolCreateLoading(false));
});
if (err?.message !== 'cancel') {
dispatch(toastError(CREATE_BIDDING_TOOL_ERROR, CREATE_BIDDING_TOOL_ERROR_TITLE));
}
});
};
Expand Down
Loading
Loading