Skip to content

Commit

Permalink
[#79] Datapoint status, datapoint callback function
Browse files Browse the repository at this point in the history
  • Loading branch information
dedenbangkit committed Feb 2, 2023
1 parent 495f949 commit d40dd75
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
23 changes: 20 additions & 3 deletions src/components/SavedSubmissionList.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { useState, useEffect } from 'react';
import { Row, Col, Space, Button, Spin } from 'antd';
import { FaCheckCircle } from 'react-icons/fa';
import { MdPendingActions } from 'react-icons/md';
import ds from '../lib/db';

const SavedSubmissionList = ({ formId }) => {
Expand Down Expand Up @@ -51,20 +53,33 @@ const SavedSubmissionList = ({ formId }) => {
}

return (
<Row gutter={[16, 16]}>
<Row>
{dataPoints.map((x, xi) => (
<Col
key={xi}
className="arf-draft-list"
className={
x.current ? 'arf-draft-list arf-current' : 'arf-draft-list'
}
span={24}
>
<Row>
<Col
span={24}
span={20}
className="arf-draft-title"
>
{xi + 1}. {x.name}
</Col>
<Col
span={4}
align="right"
className="arf-draft-status"
>
{x.submitted ? (
<FaCheckCircle color="green" />
) : (
<MdPendingActions color="#ff6000" />
)}
</Col>
</Row>
<Row>
<Col
Expand All @@ -73,12 +88,14 @@ const SavedSubmissionList = ({ formId }) => {
>
<Space>
<Button
disabled={x.submitted}
size="small"
onClick={() => x.load()}
>
Load
</Button>
<Button
disabled={x.submitted}
size="small"
onClick={() => onDeleteDataPoint(x.remove)}
type="danger"
Expand Down
15 changes: 14 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,20 @@ export const Webform = ({
const onComplete = (values) => {
if (onFinish) {
const { dpName, dpGeo } = generateDataPointName(dataPointName);
onFinish({ ...values, datapoint: { name: dpName, geo: dpGeo } });
const refreshForm = () => {
if (autoSave?.name) {
ds.getId(autoSave.name).then((d) => {
form.resetFields();
ds.status(d.id, 1);
});
} else {
form.resetFields();
}
};
onFinish(
{ ...values, datapoint: { name: dpName, geo: dpGeo } },
refreshForm
);
}
};

Expand Down
5 changes: 4 additions & 1 deletion src/lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import GlobalStore from './store';
const db = new Dexie('arf');

db.version(1).stores({
data: 'id++, name, formId, current, created',
data: 'id++, name, formId, current, submitted, created',
values: 'id++, [dataId+questionId+repeat], value',
});

Expand Down Expand Up @@ -41,6 +41,7 @@ const newData = (formId, name) => {
name,
formId,
current: 1,
submitted: 0,
created: Date.now(),
});
GlobalStore.update((s) => {
Expand Down Expand Up @@ -220,6 +221,8 @@ const ds = {
get: (id) => getValue({ dataId: id }),
remove: deleteData,
disable: () => db.data.where({ current: 1 }).modify({ current: 0 }),
status: (id, submitted) =>
db.data.where({ id: id }).modify({ submitted: submitted }),
value: {
get: ({ dataId, questionId }) =>
getValue({ dataId: dataId, questionId: questionId }),
Expand Down
6 changes: 5 additions & 1 deletion src/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,11 @@ button.repeat-delete-btn .icon {
/* Submission List Drawer */
.draft-list {
border-bottom: 1px solid rgba(5, 5, 5, 0.06);
padding-bottom: 20px;
padding: 10px;
}
.draft-list.current {
border-top: 1px solid #d0d0d0;
background-color: #e3e3e3;
}
.draft-list .draft-title {
padding-bottom: 10px;
Expand Down
1 change: 1 addition & 0 deletions src/support/LeftDrawer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const LeftDrawer = ({ title, content }) => {
<DrawerToggle />
<Drawer
className="arf-submissions-drawer-container"
bodyStyle={{ padding: '0px', borderTop: '1px solid #d0d0d0' }}
title={title || 'Submissions'}
placement="left"
width={windowWidth > 700 ? '450' : '75%'}
Expand Down

0 comments on commit d40dd75

Please sign in to comment.