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

Contract tool: MVP #1058

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
REACT_APP_WEBMAP_DOMAIN=https://beta-map.treetracker.org
REACT_APP_API_ROOT=https://dev-k8s.treetracker.org/api/admin
REACT_APP_CONTRACTS_ROOT=https://dev-k8s.treetracker.org/contract
REACT_APP_EARNINGS_ROOT=https://dev-k8s.treetracker.org/earnings
REACT_APP_FIELD_DATA_API_ROOT=https://dev-k8s.treetracker.org/field-data
REACT_APP_GROWER_QUERY_API_ROOT=https://dev-k8s.treetracker.org/grower-account-query
Expand Down
165 changes: 165 additions & 0 deletions src/api/contracts.js
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect description

Copy link
Collaborator

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.

* @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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the / before agreements correct syntax and needed? Other calls do not have the slash.

(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
);
},
};
2 changes: 1 addition & 1 deletion src/api/treeTrackerApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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,
Expand Down
43 changes: 43 additions & 0 deletions src/common/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be spelled nursery

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
Expand Down
Loading