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

Draft: Add new protocol view #84

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
85 changes: 44 additions & 41 deletions src/components/process_protocols/VerifyProtocolInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { faChevronDown, faChevronLeft } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import styled from 'styled-components'

import { AuthContext } from '../App'
import ConfirmationModal from './ConfirmationModal'
import ProtocolForm from './validation_form/ProtocolForm'
import SectionDetails from './validation_form/SectionDetails'

const ProtocolInfoSection = styled.div`
width: 50vw;
height: 100vh;
Expand All @@ -17,7 +22,7 @@ const ProtocolInfoSection = styled.div`
right: 0;
`

const ProtocolDetails = styled.div`
const ProtocolDetailsStyle = styled.div`
padding: 20px;

h1 {
Expand Down Expand Up @@ -125,10 +130,6 @@ const ApproveAndSendViolationButton = styled(VerificationPanelButton)`
}
`

import { AuthContext } from '../App'
import ConfirmationModal from './ConfirmationModal'
import SectionDetails from './validation_form/SectionDetails'

export default (props) => {
const { parties, authPost, authGet } = useContext(AuthContext)

Expand Down Expand Up @@ -172,38 +173,40 @@ export default (props) => {
)
const ref = useRef()

// useEffect(() => {
// setFormState(
// new ValidationFormState({
// protocol: props.protocol,
// parties,
// protocolType,
// machineCount,
// })
// );
// // setMachineCount(0);
// }, [protocolType]);

// useEffect(() => {
// setFormState(
// new ValidationFormState({
// protocol: props.protocol,
// parties,
// protocolType,
// machineCount,
// })
// );
// if (machineCount === 0) {
// setMachineHash([]);
// } else if (machineCount === 1) {
// setMachineHash([{ startHash: '', endHash: '' }]);
// } else if (machineCount === 2) {
// setMachineHash([
// { startHash: '', endHash: '' },
// { startHash: '', endHash: '' },
// ]);
// }
// }, [machineCount]);
useEffect(() => {
setFormState(
new ValidationFormState({
protocol: props.protocol,
parties,
protocolType,
machineCount,
})
)

setMachineCount(protocolType == 'paper-machine' ? 1 : 0)
}, [protocolType])

useEffect(() => {
setFormState(
new ValidationFormState({
protocol: props.protocol,
parties,
protocolType,
machineCount,
})
)

if (machineCount === 0) {
setMachineHash([])
} else if (machineCount === 1) {
setMachineHash([{ startHash: '', endHash: '' }])
} else if (machineCount === 2) {
setMachineHash([
{ startHash: '', endHash: '' },
{ startHash: '', endHash: '' },
])
}
}, [machineCount])

useKeypress(['ArrowUp'], (event) => {
let lastInput = null
Expand Down Expand Up @@ -444,7 +447,7 @@ export default (props) => {
Секция {props.protocol.section?.id}
</h1>
</SectionHeader>
<ProtocolDetails>
<ProtocolDetailsStyle>
<SectionDetails
fieldStatus={fieldStatus}
handleProtocolNumberChange={handleProtocolNumberChange}
Expand All @@ -457,7 +460,7 @@ export default (props) => {
setMachineCount={setMachineCount}
setIsFinal={setIsFinal}
/>
{/* {protocolType === 'unset' ||
{protocolType === 'unset' ||
(protocolType === 'machine' && machineCount === 0) ||
(protocolType === 'paper-machine' && machineCount === 0) ? null : (
<ProtocolForm
Expand All @@ -472,7 +475,7 @@ export default (props) => {
machineHash={machineHash}
setMachineHash={setMachineHash}
/>
)} */}
)}
{protocolType !== 'unset' ? <hr /> : null}
{invalidFields || changedFields ? (
<AcceptButton disabled={invalidFields} onClick={openConfirmModal}>
Expand All @@ -482,7 +485,7 @@ export default (props) => {
<AcceptButton onClick={openConfirmModal}>Потвърди</AcceptButton>
)}
<RejectButton onClick={openRejectModal}>Отхвърли</RejectButton>
</ProtocolDetails>
</ProtocolDetailsStyle>
</ProtocolInfoSection>
</div>
)
Expand Down
66 changes: 44 additions & 22 deletions src/components/process_protocols/validation_form/ProtocolForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import React from 'react'
import styled from 'styled-components'

const ProtocolDetailsTable = styled.table`
table-layout: fixed;
table-layout: inherit;

button {
width: 100%;
box-sizing: border-box;
}

input {
width: 100%;
box-sizing: border-box;
width: 100%;
box-sizing: border-box;
border: 1px solid #ddd;
Expand Down Expand Up @@ -44,7 +42,7 @@ const ProtocolDetailsTable = styled.table`
`

const PartyResultsTable = styled.table`
table-layout: fixed;
table-layout: inherit;
width: 100%;
border-collapse: collapse;

Expand Down Expand Up @@ -107,10 +105,12 @@ const PartyResultsTable = styled.table`
`
: props.colCount === 2
? `
td:nth-child(1), th:nth-child(1) { width: 8%; }
td:nth-child(2), th:nth-child(2) { width: 72%; }
td:nth-child(1), th:nth-child(1) { width: 7%; }
td:nth-child(2), th:nth-child(2) { width: 60%; }
td:nth-child(3), th:nth-child(3) { width: 10%; }
td:nth-child(4), th:nth-child(4) { width: 10%; }
td:nth-child(5), th:nth-child(5) { width: 10%; }

`
: props.colCount === 3
? `
Expand Down Expand Up @@ -164,13 +164,13 @@ export default (props) => {
: ''
}
name={`party${party.id}paper`}
value={props.formState.resultsData[`party${party.id}paper`]}
value={props.formState.resultsData[`party${party.id}paper`] ?? ''}
onChange={props.handleResultsChange}
/>
</td>
) : null}
{[...Array(props.machineCount).keys()].map((i) => (
<td>
{[...Array(props.machineCount).keys()].map((i, index) => (
<td key={index}>
<input
type="text"
className={
Expand All @@ -182,12 +182,31 @@ export default (props) => {
}
name={`party${party.id}machine${i + 1}`}
value={
props.formState.resultsData[`party${party.id}machine${i + 1}`]
props.formState.resultsData[
`party${party.id}machine${i + 1}`
] ?? ''
}
onChange={props.handleResultsChange}
/>
</td>
))}
{props.protocolType === 'paper-machine' && (
<td>
<input
type="text"
className={
props.fieldStatus[`party${party.id}total`].invalid
? 'invalid'
: props.fieldStatus[`party${party.id}total`].changed
? 'changed'
: ''
}
name={`party${party.id}total`}
value={props.formState.resultsData[`party${party.id}total`] ?? ''}
onChange={props.handleResultsChange}
/>
</td>
)}
</tr>
)
}
Expand Down Expand Up @@ -218,7 +237,7 @@ export default (props) => {
? 'changed'
: ''
}
value={props.formState.formData[varName]}
value={props.formState.formData[varName] ?? ''}
onChange={props.handleNumberChange}
/>
)
Expand Down Expand Up @@ -348,23 +367,26 @@ export default (props) => {
<h1>РАЗПРЕДЕЛЕНИЕ НА ГЛАСОВЕТЕ ПО КАНДИДАТСКИ ЛИСТИ</h1>
<PartyResultsTable colCount={calculateColCount()}>
<thead>
<th>#</th>
<th>Име</th>
{props.protocolType === 'paper' ||
props.protocolType === 'paper-machine' ? (
<th>Х</th>
) : null}
{[...Array(props.machineCount).keys()].map((i) => (
<th>M{i + 1}</th>
))}
<tr>
<th>#</th>
<th>Име</th>
{props.protocolType === 'paper' ||
props.protocolType === 'paper-machine' ? (
<th>Х</th>
) : null}
{[...Array(props.machineCount).keys()].map((i, index) => (
<th key={index}>M{i + 1}</th>
hkdobrev marked this conversation as resolved.
Show resolved Hide resolved
))}
{props.protocolType === 'paper-machine' && <th>Общ</th>}
</tr>
</thead>
<tbody>
{props.parties
.filter((party) => (props.allParties ? true : party.isFeatured))
.map(partyRow)}
</tbody>
</PartyResultsTable>
{props.machineCount === 1 &&
{/* {props.machineCount === 1 &&
props.machineHash.length === props.machineCount ? (
<>
<hr />
Expand Down Expand Up @@ -450,7 +472,7 @@ export default (props) => {
</tbody>
</ProtocolDetailsTable>
</>
) : null}
) : null} */}
</div>
)
}
99 changes: 71 additions & 28 deletions src/components/process_protocols/validation_form/SectionDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,34 +168,77 @@ export default (props) => {
</tr>
</tbody>
</table>
hkdobrev marked this conversation as resolved.
Show resolved Hide resolved
{/* <h5 style={{margin: '10px 0'}}>Чернова ли е протоколът?</h5>
<ChooseProtocolType>
<input type="radio" id="isNotFinal" name="isFinal" value="false" onClick={() => props.setIsFinal(false)}/>
<label htmlFor="isNotFinal">Чернова</label>
<input type="radio" id="isFinal" name="isFinal" value="true" onClick={() => props.setIsFinal(true)}/>
<label htmlFor="isFinal">Оригинал</label>
</ChooseProtocolType>
<h5 style={{margin: '10px 0'}}>Изберете вид протокол</h5>
<ChooseProtocolType>
<input type="radio" id="machine" name="protocolType" value="machine" onClick={() => props.setProtocolType('machine')}/>
<label htmlFor="machine">Машинен</label>
<input type="radio" id="paper" name="protocolType" value="paper" onClick={() => props.setProtocolType('paper')}/>
<label htmlFor="paper">Хартиен</label>
<input type="radio" id="paper-machine" name="protocolType" value="paper-machine" onClick={() => props.setProtocolType('paper-machine')}/>
<label htmlFor="paper-machine">Хартиено-машинен</label>
</ChooseProtocolType>
{
props.protocolType === 'machine' || props.protocolType === 'paper-machine'?
<>
<h5 style={{margin: '10px 0'}}>Брой машини</h5>
<ChooseProtocolType>
<input type="radio" id="1machine" name="machineCount" value="1machine" onClick={() => props.setMachineCount(1)} checked={props.machineCount === 1}/>
<label htmlFor="1machine">1 машина</label>
<input type="radio" id="2machines" name="machineCount" value="2machines" onClick={() => props.setMachineCount(2)} checked={props.machineCount === 2}/>
<label htmlFor="2machines">2 машини</label>
</ChooseProtocolType>
</> : null
} */}
<h5 style={{ margin: '10px 0' }}>Чернова ли е протоколът?</h5>
<ChooseProtocolType>
<input
type="radio"
id="isNotFinal"
name="isFinal"
value="false"
onClick={() => props.setIsFinal(false)}
/>
<label htmlFor="isNotFinal">Чернова</label>
<input
type="radio"
id="isFinal"
name="isFinal"
value="true"
onClick={() => props.setIsFinal(true)}
/>
<label htmlFor="isFinal">Оригинал</label>
</ChooseProtocolType>
<h5 style={{ margin: '10px 0' }}>Изберете вид протокол</h5>
<ChooseProtocolType>
{/* <input
type="radio"
id="machine"
name="protocolType"
onClick={() => props.setProtocolType('machine')}
/>
<label htmlFor="machine">Машинен</label> */}
<input
type="radio"
id="paper"
name="protocolType"
onClick={() => props.setProtocolType('paper')}
/>
<label htmlFor="paper">Хартиен</label>
<input
type="radio"
id="paper-machine"
name="protocolType"
onClick={() => props.setProtocolType('paper-machine')}
/>
<label htmlFor="paper-machine">Хартиено-машинен</label>
</ChooseProtocolType>
{/* {props.protocolType === 'machine' ||
props.protocolType === 'paper-machine' ? (
<>
<h5 style={{ margin: '10px 0' }}>Брой машини</h5>
<ChooseProtocolType>
<input
readOnly
type="radio"
id="1machine"
name="machineCount"
value="1machine"
onClick={() => props.setMachineCount(1)}
checked={props.machineCount === 1}
/>
<label htmlFor="1machine">1 машина</label>
<input
readOnly
type="radio"
id="2machines"
name="machineCount"
value="2machines"
onClick={() => props.setMachineCount(2)}
checked={props.machineCount === 2}
/>
<label htmlFor="2machines">2 машини</label>
</ChooseProtocolType>
</>
) : null} */}
<hr />
</>
)
Expand Down
Loading