Skip to content

Commit

Permalink
upadate flowform
Browse files Browse the repository at this point in the history
  • Loading branch information
seniorITdev committed May 18, 2024
1 parent 6a93894 commit 5335f65
Show file tree
Hide file tree
Showing 15 changed files with 1,167 additions and 842 deletions.
375 changes: 263 additions & 112 deletions apps/hpc-ftsadmin/src/app/components/flow-form.tsx

Large diffs are not rendered by default.

55 changes: 38 additions & 17 deletions apps/hpc-ftsadmin/src/app/pages/add-edit/flow-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,17 @@ const YellowTooltip = styled(({ className, ...props }: TooltipProps) => (
}));

const initialFormData = {
amountUSD: 0,
amountOriginal: 0,
exchangeRateUsed: 0,
amountUSD: '',
amountOriginal: '',
exchangeRateUsed: '',
keywords: [],
flowStatus: '',
flowType: { value: 133, displayLabel: 'Standard' },
flowDescription: '',
firstReported: dayjs(),
decisionDate: null,
budgetYear: '',
flowDate: '',
flowDate: null,
contributionType: { value: 50, displayLabel: 'Financial' },
earmarkingType: '',
method: { value: 156, displayLabel: 'Traditional aid' },
Expand Down Expand Up @@ -142,7 +142,7 @@ const initialFormData = {
reporterReferenceCode: '',
reportChannel: '',
reportedOrganization: { value: '', displayLabel: '' },
reportedDate: '',
reportedDate: null,
reporterContactInformation: '',
sourceSystemRecordId: '',
reportFiles: [
Expand Down Expand Up @@ -243,6 +243,7 @@ export default (props: Props) => {
useState<boolean>(false);
const [allFieldsReviewed, setAllFieldsReviewed] = useState<boolean>(false);
const [isRestricted, setIsRestricted] = useState<boolean>(false);
const [errorCorrection, setErrorCorrection] = useState<boolean>(false);
const [parentFlow, setParentFlow] = useState<AutoCompleteSelectionType[]>([]);
const [childFlow, setChildFlow] = useState<AutoCompleteSelectionType[]>([]);
const [parentIds, setParentIds] = useState<number[]>([]);
Expand Down Expand Up @@ -350,6 +351,13 @@ export default (props: Props) => {
setIsRestricted(false);
}
};
const handleErrorCorrection = (isChecked: boolean) => {
if (isChecked) {
setErrorCorrection(true);
} else {
setErrorCorrection(false);
}
};

const initializeInputEntries = () => {
const tmpEntries = JSON.parse(JSON.stringify(initialInputEntries));
Expand Down Expand Up @@ -950,12 +958,12 @@ export default (props: Props) => {
(refileData: ReportFileType[], fileData) => {
if (fileData.type !== 'url') {
refileData.push({
title: fileData.title,
fileName: fileData.fileAssetEntity.originalname,
UploadFileUrl: fileData.fileAssetEntity.path,
fileAssetID: fileData.fileAssetID,
size: fileData.fileAssetEntity.size,
type: fileData.fileAssetEntity.mimetype,
title: fileData?.title,
fileName: fileData.fileAssetEntity?.originalname,
UploadFileUrl: fileData.fileAssetEntity?.path,
fileAssetID: fileData?.fileAssetID,
size: fileData.fileAssetEntity?.size,
type: fileData.fileAssetEntity?.mimetype,
});
}
return refileData;
Expand Down Expand Up @@ -1019,12 +1027,12 @@ export default (props: Props) => {
(refileData: ReportFileType[], fileData) => {
if (fileData.type !== 'url') {
refileData.push({
title: fileData.title,
fileName: fileData.fileAssetEntity.originalname,
UploadFileUrl: fileData.fileAssetEntity.path,
fileAssetID: fileData.fileAssetID,
size: fileData.fileAssetEntity.size,
type: fileData.fileAssetEntity.mimetype,
title: fileData?.title,
fileName: fileData.fileAssetEntity?.originalname,
UploadFileUrl: fileData.fileAssetEntity?.path,
fileAssetID: fileData?.fileAssetID,
size: fileData.fileAssetEntity?.size,
type: fileData.fileAssetEntity?.mimetype,
});
}
return refileData;
Expand Down Expand Up @@ -1625,6 +1633,7 @@ export default (props: Props) => {
overflowY: 'scroll',
position: 'sticky',
top: '100px',
zIndex: 2,
}}
>
<StyledTitle>
Expand Down Expand Up @@ -1747,6 +1756,17 @@ export default (props: Props) => {
}}
>
<StyledRestrictedCheckBox>
{!isPending && props.isEdit && (
<C.CheckBox
label="as error correction"
name="isErrorCorrectionValue"
size="small"
onChange={(e) => {
handleErrorCorrection(e.target.checked);
}}
withoutFormik
/>
)}
<C.CheckBox
name="restricted"
value={isRestricted}
Expand Down Expand Up @@ -1806,6 +1826,7 @@ export default (props: Props) => {
prevDetails={previousReportDetails}
versionData={versionData}
isRestricted={isRestricted}
errorCorrection={errorCorrection}
inputEntries={inputEntries}
flowId={flowId}
versionId={versionId}
Expand Down
12 changes: 12 additions & 0 deletions libs/hpc-data/src/lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const ABORT_ERROR = 'abort_error';
const CONFLICT_ERROR = 'conflict';
const DUPLICATE_ERROR = 'duplicate';
const USER_ERROR = 'user_error';
const CONSISTENCY_ERROR = 'consistency';

export const USER_ERROR_KEYS = [
'access.userAlreadyInvited',
Expand Down Expand Up @@ -113,3 +114,14 @@ export class DuplicateError extends Error {
export const isDuplicateError = (error: Error): error is DuplicateError =>
error instanceof DuplicateError ||
(error && (error as DuplicateError).code === DUPLICATE_ERROR);

export class ConsistencyError extends Error {
public readonly code = CONSISTENCY_ERROR;
public readonly reason: any[];
public readonly message: string;
public constructor(reason: any[], message: string) {
super(CONFLICT_ERROR);
this.reason = reason;
this.message = message;
}
}
14 changes: 10 additions & 4 deletions libs/hpc-live/src/lib/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,19 @@ export class LiveModel implements Model {
// throw new ModelError('Received unexpected result from server', json);
// }
} else {
const json = (await res.json()) as {
const x = await res.json();
const json = x as {
timestamp: Date;
otherUser: string;
code?: string;
message: errors.UserErrorKey;
details?: {
code: string;
detail: string;
table: string;
code?: string;
detail?: string;
table?: string;
flow?: flows.FlowREST;
reason?: any[];
success?: boolean;
};
};
if (json?.code === 'ConflictError') {
Expand All @@ -464,6 +468,8 @@ export class LiveModel implements Model {
json.details.detail,
json.details.table
);
} else if (json?.code === 'BadRequestError' && json.details?.reason) {
throw new errors.ConsistencyError(json.details.reason, json.message);
} else {
const message =
json?.code && json?.message
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState, useCallback, useMemo } from 'react';
import React, { useEffect, useState, useCallback, useMemo, memo } from 'react';
import {
Autocomplete,
AutocompleteProps,
Expand Down Expand Up @@ -81,6 +81,8 @@ type AsyncAutocompleteSelectProps = {
withoutFormik?: boolean;
setFieldValue?: any;
values?: any;
alreadyIsFetch?: boolean;
fetchedData?: readonly FormObjectValue[];
};

const AsyncAutocompleteSelect = ({
Expand Down Expand Up @@ -304,18 +306,11 @@ const AsyncAutocompleteSelect = ({
};
} else {
return {
displayLabel: (
responseValue as {
id: number;
name: string;
}
).name,
displayLabel: (responseValue as { id: number; name: string })
.name,
value: responseValue.id,
restricted: (
responseValue as {
restricted?: boolean;
}
).restricted,
restricted: (responseValue as { restricted?: boolean })
.restricted,
};
}
});
Expand Down Expand Up @@ -370,6 +365,8 @@ const AsyncAutocompleteSelect = ({
onChange={onChange}
entryInfo={entryInfo}
rejectInputEntry={rejectInputEntry}
alreadyIsFetch={isFetch}
fetchedData={options}
/>
);
}
Expand Down Expand Up @@ -553,6 +550,8 @@ const FormikAsyncAutocompleteSelect = ({
onChange,
entryInfo,
rejectInputEntry,
alreadyIsFetch,
fetchedData,
...otherProps
}: AsyncAutocompleteSelectProps) => {
const [open, setOpen] = useState(false);
Expand Down Expand Up @@ -624,6 +623,13 @@ const FormikAsyncAutocompleteSelect = ({
};
}, [inputValue]);

useEffect(() => {
if (fetchedData && fetchedData.length > 0 && alreadyIsFetch) {
setOptions(fetchedData);
setIsFetch(true);
}
}, [fetchedData, alreadyIsFetch]);

useEffect(() => {
let active = true;
if (
Expand Down Expand Up @@ -660,7 +666,7 @@ const FormikAsyncAutocompleteSelect = ({
(async () => {
try {
let response: APIAutocompleteResult;
if (fnPromise) {
if (fnPromise && !alreadyIsFetch) {
response = await fnPromise({
query: category ? category : debouncedInputValue,
});
Expand Down
Loading

0 comments on commit 5335f65

Please sign in to comment.