Skip to content

Commit

Permalink
Merge branch 'issues/39' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
frugge committed Oct 25, 2019
2 parents 1a5359d + fbd71ca commit 9c5b086
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 23 deletions.
8 changes: 7 additions & 1 deletion src/api/Contracts.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
// first, include axios (or similar database talker)
import { CancelToken } from 'axios'
import axios from "../bootstrap/Api";
import { CANCEL } from 'redux-saga'

// endpoint root
const root = "/contracts";

export class Contracts {
static list(payload) {
return axios.get(root, { params: payload });

const source = CancelToken.source()
const request = axios.get(root, { params: payload, cancelToken: source.token });
request[CANCEL] = () => source.cancel()
return request
}
static get(payload) {
return axios.get(`${root}/${payload.id}`, {
Expand Down
8 changes: 7 additions & 1 deletion src/api/Disputes.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
// first, include axios (or similar database talker)
import { CancelToken } from 'axios'
import axios from "../bootstrap/Api";
import { CANCEL } from 'redux-saga'

// endpoint root
const root = "/contracts/disputes";

export class Disputes {
static list(payload) {
return axios.get(`${root}/all`, { params: payload });

const source = CancelToken.source()
const request = axios.get(`${root}/all`, { params: payload, cancelToken: source.token });
request[CANCEL] = () => source.cancel()
return request
}
static get(payload) {
return axios.get(`${root}/${payload.id}?include=attachments`);
Expand Down
10 changes: 7 additions & 3 deletions src/components/common/ContractsFilters/ContractsFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Form from "../Form";
import Button from "../Button";
import { SearchIcon } from "../Icons/SearchIcon";
import statusList from "../../../assets/i18n/en/status.json"; // categories
import { getFormattedDate } from "../../../utils/helpers"; // helpers
import { getFormattedDate, log } from "../../../utils/helpers"; // helpers
import "./ContractsFilters.scss";
export class ContractsFilters extends Component {
state = {
Expand All @@ -18,9 +18,13 @@ export class ContractsFilters extends Component {
handleChange = (type, value) => {
this.setState((state) => {
const newState = { ...state, [type]: value };
value = type === 'searchText' && value === '' ? null : value
if (typeof this.props.onChange === "function") this.props.onChange(type, value);
return newState;
});
log('ContractsFilters handlechange',{type:type,value:value})


};

handleReset = () => {
Expand Down Expand Up @@ -54,7 +58,7 @@ export class ContractsFilters extends Component {
<Form.Search
onChange={(value) => this.handleChange("searchText", value)}
/>
<Button
{/* <Button
color="info"
className="jur-contracts-filter__submit-btn"
variant="contained"
Expand All @@ -63,7 +67,7 @@ export class ContractsFilters extends Component {
hoverColor="info"
>
<SearchIcon />
</Button>
</Button> */}
</div>
);
}
Expand Down
12 changes: 7 additions & 5 deletions src/components/common/DisputesFilters/DisputesFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SearchIcon } from "../Icons/SearchIcon";
import statusList from "../../../assets/i18n/en/status.json"; // status
import categories from "../../../assets/i18n/en/contractCategories.json"; // categories
import "./DisputesFilters.scss";
import { getFormattedDate } from "../../../utils/helpers"; // helpers
import { getFormattedDate, log } from "../../../utils/helpers"; // helpers
import { AppContext } from "../../../bootstrap/AppProvider"; // context

export const DisputesFilters = ( props ) => {
Expand All @@ -23,11 +23,13 @@ export const DisputesFilters = ( props ) => {

const handleChange = (type, value) => {

onChange(type, value);
value = type === 'searchText' && value === '' ? null : value
// onChange(type, value);

setState((state) => {
const newState = { ...state, [type]: value };
if (typeof onChange === "function") onChange(newState);
if (typeof onChange === "function") onChange(type, value);
//onChange(newState);
return newState;
});
};
Expand Down Expand Up @@ -90,7 +92,7 @@ export const DisputesFilters = ( props ) => {
onChange={(value) => handleChange("toDate", getFormattedDate(value))}
/>
<Form.Search onChange={(value) => handleChange("searchText", value)} />
<Button
{/* <Button
color="info"
variant="contained"
onClick={onSubmit}
Expand All @@ -99,7 +101,7 @@ export const DisputesFilters = ( props ) => {
className="can-disable"
>
<SearchIcon />
</Button>
</Button> */}
</div>
);
};
1 change: 1 addition & 0 deletions src/components/common/Form/FormDatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const FormDatePicker = ( props ) => {
selected={selectedDate}
onChange={onChange}
dateFormat="dd/MM/yyyy"
isClearable
{...rest}
/>
{error && errorMsg && <Form.ErrorMsg msg={errorMsg} />}
Expand Down
6 changes: 6 additions & 0 deletions src/components/common/Form/Forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,9 @@
}
}
}

.react-datepicker__close-icon::after {
background-color: transparent;
color: #002257;
font-size: 16px;
}
4 changes: 4 additions & 0 deletions src/components/sections/Contracts/Contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export const Contracts = ( props ) => {
field: type,
value
});

if (!(type === 'searchText' && value !== null && value.length < 3)) {
handleFilterSubmit()
}
};
const handleFilterSubmit = () => {
if (
Expand Down
7 changes: 7 additions & 0 deletions src/components/sections/Disputes/Disputes.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ export const Disputes = ( props ) => {
field: type,
value
});


if (!(type === 'searchText' && value !== null && value.length < 3)) {
log('handleFilterChange ', type)
handleFilterSubmit()
}

};
const handleFilterSubmit = () => {
global.drizzle.store.dispatch({ type: FETCH_DISPUTES });
Expand Down
4 changes: 2 additions & 2 deletions src/sagas/Contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export function* fetchContracts() {
status && typeof status.value !== "undefined" ? status.value : null,
from: fromDate,
to: toDate,
q: searchText,
query: searchText,
page,
...orderby
});
Expand Down Expand Up @@ -604,7 +604,7 @@ export default function* contractSagas() {
yield takeEvery(PUT_CONTRACT, updateContract);
yield takeEvery(API_GET_CONTRACT, getContract);
yield takeLatest(API_DELETE_CONTRACT, deleteContract);
yield takeEvery(FETCH_CONTRACTS, fetchContracts);
yield takeLatest(FETCH_CONTRACTS, fetchContracts);
yield takeEvery(CONTRACT_ISSUE, handleContractIssues);
yield takeLatest(CONTRACT_DELETED, onContractDelete);
yield takeLatest(RESET_CONTRACT, onContractReset);
Expand Down
6 changes: 3 additions & 3 deletions src/sagas/Dispute.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function* fetchDisputes() {
status: status && typeof status.value !== "undefined" ? status.value : null,
from: fromDate,
to: toDate,
q: searchText
query: searchText
});
try {
const response = yield call(Disputes.list, {
Expand All @@ -121,7 +121,7 @@ export function* fetchDisputes() {
category && typeof category.value !== "undefined"
? category.value
: null,
q: searchText,
query: searchText,
show: mine ? "my" : "all",
page,
...orderby
Expand Down Expand Up @@ -191,7 +191,7 @@ export default function* disputeSagas() {
log("run", "DisputeSagas");
yield takeEvery(API_GET_DISPUTE, getDispute);
yield takeLatest(API_DELETE_DISPUTE, deleteDispute);
yield takeEvery(FETCH_DISPUTES, fetchDisputes);
yield takeLatest(FETCH_DISPUTES, fetchDisputes);
yield takeLatest(DISPUTE_DELETED, onDisputeDelete);
yield takeLatest(API_CATCH, resetUpdating);
yield takeLatest(SET_DISPUTE, resetUpdating);
Expand Down
20 changes: 12 additions & 8 deletions src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,18 @@ export const ethToStore = ( value ) => {
};

export const getFormattedDate = (date) => {
let year = date.getFullYear();
let month = (1 + date.getMonth()).toString().padStart(2, "0");
let day = date
.getDate()
.toString()
.padStart(2, "0");

return `${year}-${month}-${day}`;
if (date) {
let year = date.getFullYear();
let month = (1 + date.getMonth()).toString().padStart(2, "0");
let day = date
.getDate()
.toString()
.padStart(2, "0");

return `${year}-${month}-${day}`;
}
return null;

};

export const capitalize = (string) =>
Expand Down

0 comments on commit 9c5b086

Please sign in to comment.