Skip to content

Commit

Permalink
Separate out queue and LIMS APIs from Redux
Browse files Browse the repository at this point in the history
  • Loading branch information
axelboc authored and marcus-oscarsson committed Jul 8, 2024
1 parent e6e310f commit ce1043c
Show file tree
Hide file tree
Showing 18 changed files with 306 additions and 511 deletions.
34 changes: 11 additions & 23 deletions ui/src/actions/login.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable promise/catch-or-return */
/* eslint-disable promise/prefer-await-to-then */

import fetch from 'isomorphic-fetch';
import { fetchBeamInfo, fetchBeamlineSetup } from '../api/beamline';
import { fetchDiffractometerInfo } from '../api/diffractometer';
import { fetchLogMessages } from '../api/log';
Expand All @@ -16,6 +14,7 @@ import { fetchSampleChangerInitialState } from '../api/sampleChanger';
import { fetchHarvesterInitialState } from '../api/harvester';
import { fetchImageData, fetchShapes } from '../api/sampleview';
import { fetchRemoteAccessState } from '../api/remoteAccess';
import { sendSelectProposal } from '../api/lims';

export function setLoginInfo(loginInfo) {
return {
Expand Down Expand Up @@ -50,7 +49,7 @@ export function hideProposalsForm() {
};
}

export function selectProposal(prop) {
export function selectProposalAction(prop) {
return {
type: 'SELECT_PROPOSAL',
proposal: prop,
Expand All @@ -61,29 +60,18 @@ export function setInitialState(data) {
return { type: 'SET_INITIAL_STATE', data };
}

export function postProposal(number) {
return fetch('mxcube/api/v0.1/lims/proposal', {
method: 'POST',
credentials: 'include',
headers: {
Accept: 'application/json',
'Content-type': 'application/json',
},
body: JSON.stringify({ proposal_number: number }),
});
}

export function sendSelectProposal(number, navigate) {
return (dispatch) => {
postProposal(number).then((response) => {
if (response.status >= 400) {
export function selectProposal(number, navigate) {
return async (dispatch) => {
try {
await sendSelectProposal(number);
navigate('/');
dispatch(selectProposalAction(number));
} catch (error) {
if (error.status >= 400) {
dispatch(showErrorPanel(true, 'Server refused to select proposal'));
navigate('/login');
} else {
navigate('/');
dispatch(selectProposal(number));
}
});
}
};
}

Expand Down
Loading

0 comments on commit ce1043c

Please sign in to comment.