Skip to content

Commit

Permalink
WIP: bulk submit cont [gh-1132]
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbiang888 committed Jan 14, 2021
1 parent f9f09d1 commit 0cd80b6
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 14 deletions.
1 change: 1 addition & 0 deletions api/controller/contributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export class UpdateContributionDto implements IUpdateContributionAttrs {

export async function updateContribution(request: IRequest, response: Response, next: Function) {
try {
console.log(response);
checkCurrentUser(request);
const updateContributionDto = Object.assign(new UpdateContributionDto(), {
...request.body,
Expand Down
47 changes: 47 additions & 0 deletions api/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,53 @@ export const AppRoutes = [
action: contributions.updateContribution
},

/**
* @swagger
* /bulk-update-contributions:
* put:
* summary: Bulk update contributions
* tags:
* - Contributions
* security:
* - cookieAuth: []
* produces:
* - application/json
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: array
* items:
* type: object
* properties:
* currentUserId:
* type: integer
* id:
* type: integer
* status:
* type: string
* responses:
* 200:
* description: Success response (X of X updated, X invalid)
* content:
* application/json:
* schema:
* type: object
* properties:
* message:
* type: string
* 422:
* $ref: '#/components/responses/UnprocessableEntity'
*
*/
// TODO: verify swagger is correct
{
path: '/contributions/:id',
method: 'put',
action: contributions.updateContribution
},

/**
* @swagger
* /contributions/{id}:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const buttonWrapper = css`
const actionInfo = (name, buttonType, onClick, isFreeAction = undefined) =>
isFreeAction
? { icon: 'none', name, buttonType, onClick, isFreeAction }
: { icon: 'none', name, buttonType, onClick };
: { icon: 'none', name, buttonType, onClick, position: 'row' };

const columns = isGovAdmin => {
const cols = [
Expand Down Expand Up @@ -118,11 +118,27 @@ const columns = isGovAdmin => {
class ContributionsTable extends React.Component {
constructor(props) {
super(props);
this.state = {
itemsToSubmit: null,
};
props.getContributions({
governmentId: props.govId,
currentUserId: props.userId,
campaignId: props.campaignId,
});
this.updateItemsToSubmit = this.updateItemsToSubmit.bind(this);
}

updateItemsToSubmit(items) {
if (items.length > 0) {
this.setState({
itemsToSubmit: items,
});
} else {
this.setState({
itemsToSubmit: null,
});
}
}

render() {
Expand All @@ -144,9 +160,14 @@ class ContributionsTable extends React.Component {
const isLoading = isListLoading && !Array.isArray(contributionList);

const actions = [
actionInfo('View', 'submit', (event, rowData) => {
history.push(`/contributions/${rowData.id}`);
}),
actionInfo(
'View',
'submit',
(event, rowData) => {
history.push(`/contributions/${rowData.id}`);
},
false
),
];

const components = {
Expand Down Expand Up @@ -253,6 +274,14 @@ class ContributionsTable extends React.Component {
options={{
pageSize: filterOptions.perPage || 50,
showTitle: false,
actionsColumnIndex: -1,
selection: true,
selectionProps: rowData => {
return {
disabled: rowData.status === 'Submitted',
color: 'primary',
};
},
}}
actions={actions}
components={components}
Expand All @@ -275,18 +304,30 @@ class ContributionsTable extends React.Component {
pageNumber={filterOptions.page || 0}
totalRows={total}
onChangePage={handleOnChangePage}
// eslint-disable-next-line no-use-before-define
onChangeRowsPerPage={handleOnRowsPerPageChange}
toolbarAction={
!isGovAdmin ? (
<Button
buttonType="green"
onClick={() => history.push({ pathname: '/contributions/add' })}
>
Add New Contribution
</Button>
<>
<Button
buttonType="green"
onClick={() =>
history.push({ pathname: '/contributions/add' })
}
>
Add New Contribution
</Button>
{this.state.itemsToSubmit && (
<Button
buttonType="green"
onClick={() => console.log(this.state.itemsToSubmit)}
>
bulk submit
</Button>
)}
</>
) : null
}
onSelectionChange={items => this.updateItemsToSubmit(items)}
/>
</PageHoc>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,6 @@ export const validate = values => {
checkNumber,
occupation,
occupationLetterDate,
employerName,
employerCity,
employerState,
subTypeOfContribution,
inKindType,
lastName,
Expand Down
6 changes: 6 additions & 0 deletions app/src/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,12 @@ export function updateContribution(contributionAttrs) {
);
}

// path: '/bulk-update-contributions'
// method: 'put',
export function bulkUpdateContribution(contributionAttrs) {
return put(`${baseUrl()}/bulk-update-contributions`, contributionAttrs);
}

// path: '/contributions/new',
// method: 'post',
export function createContribution(contributionAttrs) {
Expand Down
1 change: 1 addition & 0 deletions app/src/components/ContributorMatchPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class contributorMatchPicker extends React.Component {
}

handleSubmit() {
// TODO: does this need to update this?
this.props.updateMatchForContribution({
contributionId: this.props.contributionId,
matchId: this.state.pages[this.state.currentPage].id,
Expand Down
1 change: 1 addition & 0 deletions app/src/components/Forms/ContributionReady/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class ContributionReadyForm extends React.Component {
<PageTransitionImage />
) : (
<>
<h1>nice</h1>
<ViewHeaderSection
campaignName={values.campaignName || campaignName}
isCampAdmin={isCampAdmin}
Expand Down
1 change: 1 addition & 0 deletions app/src/components/Table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const Table = ({
}
: undefined
}
// TODO: here?
action={toolbarAction}
{...toolBarProps}
/>
Expand Down
2 changes: 2 additions & 0 deletions app/src/state/ducks/contributions.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,12 @@ export function createContribution(contributionAttrs) {
}

export function updateContribution(contributionAttrs) {
// TODO: duplicate for bulk submission
return async (dispatch, getState, { api, schema }) => {
dispatch(actionCreators.updateContribution.request());
try {
const response = await api.updateContribution(contributionAttrs);
console.log({ contributionAttrs, response });
if (response.status === 204) {
let status = '';
if (contributionAttrs.status) {
Expand Down

0 comments on commit 0cd80b6

Please sign in to comment.