-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
Contract tool: MVP #1058
base: master
Are you sure you want to change the base?
Contract tool: MVP #1058
Changes from all commits
2debf3d
772031a
915a98f
30f84d4
2fa277d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
import axios from 'axios'; | ||
import { session } from '../models/auth'; | ||
import { handleResponse, handleError } from './apiUtils'; | ||
|
||
const apiUrl = `${process.env.REACT_APP_CONTRACTS_ROOT}`; | ||
const Axios = axios.create({ baseURL: apiUrl }); | ||
|
||
export default { | ||
/** | ||
* @function getContracts | ||
* @description Get Contracts from the API | ||
* @returns {Promise} | ||
*/ | ||
async getContracts(params) { | ||
const headers = { | ||
'content-type': 'application/json', | ||
Authorization: session.token, | ||
}; | ||
|
||
return Axios.get(`contract`, { params, headers }).then((res) => res.data); | ||
}, | ||
|
||
/** | ||
* @function createContract | ||
* @description Get Contracts from the API | ||
* @returns {Promise} | ||
*/ | ||
async createContract(params) { | ||
const headers = { | ||
'content-type': 'application/json', | ||
Authorization: session.token, | ||
}; | ||
|
||
// EXAMPLE POST | ||
// { | ||
// "agreement_id": "7bf1f932-2474-4211-8a07-a764ca95c80f", | ||
// "worker_id": "93a026d2-a511-404f-958c-a0a36892af0f", | ||
// "notes": "test contract notes" | ||
// } | ||
|
||
return Axios.post(`contract`, { params, headers }).then((res) => res.data); | ||
}, | ||
|
||
/** | ||
* @function getContractAgreements | ||
* @description Get Contracts from the API | ||
* @returns {Promise} | ||
*/ | ||
async getContractAgreements(params) { | ||
const headers = { | ||
'content-type': 'application/json', | ||
Authorization: session.token, | ||
}; | ||
|
||
return Axios.get(`agreement`, { params, headers }).then((res) => res.data); | ||
}, | ||
|
||
/** | ||
* @function createContractAgreement | ||
* @description Get Contracts from the API | ||
* @returns {Promise} | ||
*/ | ||
async createContractAgreement(agreement) { | ||
const abortController = new AbortController(); | ||
const headers = { | ||
'content-type': 'application/json', | ||
Authorization: session.token, | ||
}; | ||
|
||
// EXAMPLE POST | ||
// { | ||
// "type": "grower", | ||
// "owner_id": "08c71152-c552-42e7-b094-f510ff44e9cb", | ||
// "funder_id":"c558a80a-f319-4c10-95d4-4282ef745b4b", | ||
// "consolidation_rule_id": "6ff67c3a-e588-40e3-ba86-0df623ec6435", | ||
// "name": "test agreement", | ||
// "species_agreement_id": "e14b78c8-8f71-4c42-bb86-5a7f71996336" | ||
// } | ||
|
||
try { | ||
const query = `${apiUrl}/agreement`; | ||
|
||
const result = await fetch(query, { | ||
method: 'POST', | ||
headers, | ||
body: JSON.stringify(agreement), | ||
signal: abortController?.signal, | ||
}).then(handleResponse); | ||
|
||
console.log('result ----', result); | ||
return result; | ||
} catch (error) { | ||
handleError(error); | ||
} | ||
|
||
// const result = await Axios.post(`/agreement`, { | ||
// body: JSON.stringify(params), | ||
// headers, | ||
// }).then((res) => res.data); | ||
}, | ||
|
||
/** | ||
* @function patchContractAgreement | ||
* @description Patch earning from the API | ||
* | ||
* @param {object} earning - earning to patch | ||
* @returns {Promise} | ||
*/ | ||
async patchContractAgreement(contract) { | ||
const headers = { | ||
'content-type': 'application/json', | ||
Authorization: session.token, | ||
}; | ||
|
||
return Axios.patch(`/agreement`, contract, { headers }).then( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the |
||
(res) => res.data | ||
); | ||
}, | ||
|
||
/** | ||
* @function createConsolidationRule | ||
* @description Get Contracts from the API | ||
* @returns {Promise} | ||
*/ | ||
async createConsolidationRule(params) { | ||
const headers = { | ||
'content-type': 'application/json', | ||
Authorization: session.token, | ||
}; | ||
|
||
// EXAMPLE POST | ||
// { | ||
// "name": "test", | ||
// "owner_id": "af7c1fe6-d669-414e-b066-e9733f0de7a8", | ||
// "lambda": "something" | ||
// } | ||
|
||
return Axios.post(`contract/consolidation_rule`, { params, headers }).then( | ||
(res) => res.data | ||
); | ||
}, | ||
|
||
/** | ||
* @function createSpeciesAgreement | ||
* @description Get Contracts from the API | ||
* @returns {Promise} | ||
*/ | ||
async createSpeciesAgreement(params) { | ||
const headers = { | ||
'content-type': 'application/json', | ||
Authorization: session.token, | ||
}; | ||
|
||
// EXAMPLE POST | ||
// { | ||
// "name": "test species agreement", | ||
// "owner_id": "af7c1fe6-d669-414e-b066-e9733f0de7a8", | ||
// "description": "test species agreement description" | ||
// } | ||
|
||
return Axios.post(`contract/species_agreement`, { params, headers }).then( | ||
(res) => res.data | ||
); | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,7 @@ export default { | |
lon: capture.lon, | ||
gps_accuracy: capture.gps_accuracy, | ||
captured_at: capture.captured_at, | ||
note: capture.note ? capture.note : null, | ||
note: capture.note ? capture.note : ' ', // temporary measure because the api requires a non-empty string, but adding notes is not in the UX yet | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not push this change - we should get the constraint removed from the API instead, unless it's a deliberate change in behaviour. |
||
age: age, | ||
morphology, | ||
species_id: speciesId, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,49 @@ export const verificationStatesArr = [ | |
verificationStates.REJECTED, | ||
]; | ||
|
||
export const CONTRACT_STATUS = { | ||
all: 'all', | ||
unsigned: 'unsigned', // db default state | ||
signed: 'signed', | ||
completed: 'completed', | ||
aborted: 'aborted', | ||
cancelled: 'cancelled', | ||
}; | ||
|
||
export const COORDINATOR_ROLES = { | ||
all: 'all', | ||
supervisor: 'supervisor', | ||
area_manager: 'area_manager', | ||
}; | ||
|
||
export const CURRENCY = { | ||
all: 'all', | ||
USD: 'USD', | ||
SLL: 'SLL', | ||
}; | ||
|
||
export const AGREEMENT_STATUS = { | ||
all: 'all', | ||
planning: 'planning', // db default state | ||
open: 'open', | ||
closed: 'closed', | ||
aborted: 'aborted', | ||
}; | ||
|
||
export const AGREEMENT_TYPE = { | ||
all: 'all', | ||
grower: 'grower', | ||
nursury: 'nursury', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be spelled |
||
village_champion: 'village_champion', | ||
}; | ||
|
||
export const SPECIES_TYPE = { | ||
other: 'other', | ||
any: 'any', | ||
specific: 'specific', | ||
genus: 'genus', | ||
}; | ||
|
||
// These are the default min/max dates for the MUI KeyboardDatePicker component | ||
// See https://material-ui-pickers.dev/api/KeyboardDatePicker | ||
// If we set minDate or maxDate to null on this component, the fwd/back buttons are disabled | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the descriptions need updating.