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

refactor: move signatures to review/preview section #7114

Merged
merged 35 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3fc91fc
Revert "chore(deps): update dependency lint-staged to v15 (#6942)"
Zangetsu101 May 27, 2024
db02f13
feat: allow countryconfig to define preview section
Zangetsu101 May 27, 2024
af02402
feat: render preview section in review page
Zangetsu101 May 27, 2024
3666c5d
feat: create SIGNATURE form field type
Zangetsu101 May 27, 2024
a691fbd
refactor: remove unused color prop
Zangetsu101 May 27, 2024
fac0ac7
feat: add SIGNATURE field to FormFieldGenerator
Zangetsu101 May 27, 2024
990175a
refactor: pass props to underlying input element
Zangetsu101 May 27, 2024
3be2e5a
fix: change imageUploader's type to be of a button
Zangetsu101 May 28, 2024
59e7d0a
feat: forward props to SignatureUploader
Zangetsu101 May 28, 2024
d00e840
feat: show required error message
Zangetsu101 May 28, 2024
808c196
fix: hide preview section from "review values"
Zangetsu101 May 28, 2024
551c0ec
feat: add maxSizeMb & allowedFileFormats config
Zangetsu101 May 30, 2024
4c979df
refactor: remove informantsSignatureURI
Zangetsu101 May 31, 2024
b41ef3c
fix: add marriage event to ReviewForm component
Zangetsu101 Jun 3, 2024
0d523e2
feat: provide initial values for preview section
Zangetsu101 Jun 3, 2024
790aa3e
feat: include review section from definition
Zangetsu101 Jun 4, 2024
3a52687
feat: manage review/preview section on form review
Zangetsu101 Jun 4, 2024
f2942ec
refactor: pass form def as prop to ReviewSection
Zangetsu101 Jun 4, 2024
60ef92e
refactor: remove signature uri references
Zangetsu101 Jun 4, 2024
775957b
feat: include preview/review sections
Zangetsu101 Jun 4, 2024
92cf121
chore: remove remaining uri references
Zangetsu101 Jun 5, 2024
2392756
feat: validate review/preview sections in form
Zangetsu101 Jun 5, 2024
b9342f3
chore: pass form definition to ReviewSection
Zangetsu101 Jun 6, 2024
51bba6a
test: update query selector for file upload
Zangetsu101 Jun 7, 2024
c027374
chore: use sections from provided form
Zangetsu101 Jun 10, 2024
ca3736f
test: update mock form values
Zangetsu101 Jun 10, 2024
3e1f23b
Merge branch 'develop' into ocrvs-6821
Zangetsu101 Jun 10, 2024
01853bd
chore: fix typo in directory name
Zangetsu101 Jun 12, 2024
9cd3dba
Merge branch 'develop' into ocrvs-6821
Zangetsu101 Jun 14, 2024
9f12804
chore: remove default review/preview sections
Zangetsu101 Jun 14, 2024
88ff8f0
fix: import paths
Zangetsu101 Jun 14, 2024
9a44657
docs: breaking change about review/preview section
Zangetsu101 Jun 14, 2024
c1e1e4e
test: add review/preview section in mock forms
Zangetsu101 Jun 19, 2024
b388094
Merge branch 'develop' into ocrvs-6821
Zangetsu101 Jun 25, 2024
3773ac2
Merge branch 'develop' into ocrvs-6821
Zangetsu101 Jul 8, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,15 @@ class DocumentUploaderWithOptionComp extends React.Component<

Zangetsu101 marked this conversation as resolved.
Show resolved Hide resolved
return (
<UploadWrapper>
<div id="upload-error">
{this.state.errorMessage && (
{this.state.errorMessage && (
<div id="upload-error">
<ErrorText>
{(requiredErrorMessage &&
intl.formatMessage(requiredErrorMessage)) ||
this.state.errorMessage}
</ErrorText>
)}
</div>
</div>
)}

<DocumentListPreview
processingDocuments={this.state.filesBeingProcessed}
Expand All @@ -312,11 +312,13 @@ class DocumentUploaderWithOptionComp extends React.Component<
.length === 1 ? (
<FullWidthImageUploader
id="upload_document"
title={intl.formatMessage(formMessages.addFile)}
name={this.props.name}
onClick={(e) => !this.isValid() && e.preventDefault()}
handleFileChange={this.handleFileChange}
onChange={this.handleFileChange}
disabled={this.state.filesBeingProcessed.length > 0}
/>
>
{intl.formatMessage(formMessages.addFile)}
</FullWidthImageUploader>
) : (
<Flex>
<Select
Expand All @@ -331,11 +333,13 @@ class DocumentUploaderWithOptionComp extends React.Component<
/>
<DocumentUploadButton
id="upload_document"
title={intl.formatMessage(formMessages.addFile)}
name={this.props.name}
onClick={(e) => !this.isValid() && e.preventDefault()}
handleFileChange={this.handleFileChange}
onChange={this.handleFileChange}
disabled={this.state.filesBeingProcessed.length > 0}
/>
>
{intl.formatMessage(formMessages.addFile)}
</DocumentUploadButton>
</Flex>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type IFullProps = {

const SimpleDocumentUploaderComponent = ({
allowedDocType,
name,
onUploadingStateChanged,
intl,
previewTransformer,
Expand Down Expand Up @@ -167,9 +168,11 @@ const SimpleDocumentUploaderComponent = ({
{(!files || !files.data) && (
<DocumentUploader
id="upload_document"
title={intl.formatMessage(messages.uploadFile)}
handleFileChange={handleFileChange}
/>
name={name}
onChange={handleFileChange}
>
{intl.formatMessage(messages.uploadFile)}
</DocumentUploader>
)}
</>
)
Expand Down
58 changes: 43 additions & 15 deletions packages/client/src/components/form/FormFieldGenerator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import {
ISelectFormFieldWithOptions,
ITextFormField,
Ii18nTextFormField,
Ii18nNumberFormField,
LINK,
BULLET_LIST,
NUMBER,
Expand All @@ -78,7 +77,6 @@ import {
RADIO_GROUP_WITH_NESTED_FIELDS,
Ii18nRadioGroupWithNestedFieldsFormField,
LOCATION_SEARCH_INPUT,
Ii18nTextareaFormField,
TEXT,
DATE_RANGE_PICKER,
IDateRangePickerValue,
Expand All @@ -88,7 +86,8 @@ import {
DIVIDER,
HEADING3,
SUBSECTION_HEADER,
HIDDEN
HIDDEN,
SIGNATURE
} from '@client/forms'
import { getValidationErrorsForForm, Errors } from '@client/forms/validation'
import { InputField } from '@client/components/form/InputField'
Expand Down Expand Up @@ -128,9 +127,13 @@ import { UserDetails } from '@client/utils/userUtils'
import { VerificationButton } from '@opencrvs/components/lib/VerificationButton'
import { useOnlineStatus } from '@client/utils'
import { useNidAuthentication } from '@client/views/OIDPVerificationCallback/utils'
import { BulletList, Divider } from '@opencrvs/components'
import { BulletList, Divider, InputLabel, Stack } from '@opencrvs/components'
import { Heading2, Heading3 } from '@opencrvs/components/lib/Headings/Headings'
import { SignatureUploader } from './SignatureField/SignatureUploader'

const SignatureField = styled(Stack)`
margin-top: 8px;
`
const fadeIn = keyframes`
from { opacity: 0; }
to { opacity: 1; }
Expand Down Expand Up @@ -436,7 +439,7 @@ const GeneratedInputField = React.memo<GeneratedInputFieldProps>(
<InputField {...inputFieldProps}>
<TextArea
{...inputProps}
maxLength={(fieldDefinition as Ii18nTextareaFormField).maxLength}
maxLength={fieldDefinition.maxLength}
value={value.toString()}
/>
</InputField>
Expand Down Expand Up @@ -512,14 +515,13 @@ const GeneratedInputField = React.memo<GeneratedInputFieldProps>(
if (e.key.match(REGEXP_NUMBER_INPUT_NON_NUMERIC)) {
e.preventDefault()
}
const maxLength = (fieldDefinition as Ii18nNumberFormField)
.maxLength
const maxLength = fieldDefinition.maxLength
if (maxLength && e.currentTarget.value.length >= maxLength) {
e.preventDefault()
}
}}
value={inputProps.value as string}
maxLength={(fieldDefinition as Ii18nNumberFormField).maxLength}
maxLength={fieldDefinition.maxLength}
onWheel={(event: React.WheelEvent<HTMLInputElement>) => {
event.currentTarget.blur()
}}
Expand Down Expand Up @@ -629,6 +631,37 @@ const GeneratedInputField = React.memo<GeneratedInputFieldProps>(
/>
)
}
if (fieldDefinition.type === SIGNATURE) {
const {
name,
helperText,
required,
label,
maxSizeMb,
allowedFileFormats
} = fieldDefinition
return (
<SignatureField direction="column" gap={8} alignItems="start">
<InputLabel
{...inputFieldProps}
htmlFor={name}
inputDescriptor={helperText}
>
{label}
</InputLabel>
<SignatureUploader
{...inputProps}
name={name}
modalTitle={label}
value={value as string}
maxSizeMb={maxSizeMb}
allowedFileFormats={allowedFileFormats}
required={required}
onChange={(sig) => onSetFieldValue(name, sig)}
/>
</SignatureField>
)
}
return (
<InputField {...inputFieldProps}>
<TextInput
Expand Down Expand Up @@ -664,10 +697,7 @@ const GeneratedInputField = React.memo<GeneratedInputFieldProps>(

GeneratedInputField.displayName = 'MemoizedGeneratedInputField'

const mapFieldsToValues = (
fields: IFormField[],
userDetails: UserDetails | null
) =>
const mapFieldsToValues = (fields: IFormField[]) =>
fields.reduce((memo, field) => {
let fieldInitialValue = field.initialValue as IFormFieldValue

Expand Down Expand Up @@ -1184,9 +1214,7 @@ export const FormFieldGenerator: React.FC<IFormSectionProps> = (props) => {

return (
<Formik<IFormSectionData>
initialValues={
props.initialValues ?? mapFieldsToValues(props.fields, userDetails)
}
initialValues={props.initialValues ?? mapFieldsToValues(props.fields)}
onSubmit={() => {}}
validate={(values) =>
getValidationErrorsForForm(
Expand Down
Loading
Loading