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

PLT-6763 FE: Auditors sign certificates #8

Merged
merged 21 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
56c3136
WIP
amnambiar Sep 1, 2023
d38168b
PLT-6763 Auditor L1 Certificate metadata form - optimized auditor rep…
amnambiar Sep 4, 2023
01a1968
PLT-6763 Fixed API
amnambiar Sep 4, 2023
440aaab
PLT-6763 Minor fixes
amnambiar Sep 4, 2023
20e0eb0
PLT-6763 AI review comments
amnambiar Sep 7, 2023
62c5b34
PLT-6763 AI Review comment
amnambiar Sep 7, 2023
8910510
PLT-6763 AI review comments
amnambiar Sep 7, 2023
6934b75
PLT-6763 Fixed error display in Dapp Script fields; fixed error handling
amnambiar Sep 9, 2023
0e675ce
PLT-6763 Removed dependecy array
amnambiar Sep 9, 2023
79929d0
PLT-6763 Review fixes + validation pattern updates
amnambiar Sep 12, 2023
140b618
PLT-6763 Fix to handle 204 in POST of l1-Certificate and l2-certifica…
amnambiar Sep 12, 2023
f1fd57b
Update src/pages/auditing/reportUpload/reportUpload.schema.tsx
amnambiar Sep 13, 2023
4310c03
PLT-6763 Limit name to be upto 64 characters
amnambiar Sep 13, 2023
b81bcca
Merge branch 'PLT-6763' of https://github.com/input-output-hk/dapps-c…
amnambiar Sep 13, 2023
e1c4a2d
Merge branch 'master' of https://github.com/input-output-hk/dapps-cer…
amnambiar Sep 13, 2023
23ff990
PLT-6763 fixed merge conflict
amnambiar Sep 13, 2023
8b29716
PLT-6763 Resolved incorrect code after commit resolve
amnambiar Sep 13, 2023
ff3047b
PLT-6763 Schema corrections and payload fixes
amnambiar Sep 19, 2023
50c726b
Merge branch 'master' of https://github.com/input-output-hk/dapps-cer…
amnambiar Sep 19, 2023
b1bc998
PLT-6763 Removed Subject from Certification Metadata as part of updat…
amnambiar Sep 19, 2023
31f5293
PLT-6763 Temporary hack in place to get this working with BE PR#90#94
amnambiar Sep 21, 2023
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
203 changes: 203 additions & 0 deletions src/components/CertificationForm/CertificationForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
import { useCallback, useEffect } from "react";
import Button from "components/Button/Button";
import { Form } from "compositions/Form/Form";
import { Input } from "compositions/Form/components/Input";
import DAPPScript, { IInfo } from "components/DAPPScript/DAPPScript";
import TextArea from "components/TextArea/TextArea";
import { Option } from "components/Dropdown/Dropdown";
import { useFieldArray } from "react-hook-form";
import Dropdown from "components/Dropdown/Dropdown";

export const fieldArrayName: string = "dAppScripts";

interface IFieldInfo {
label: string;
type: string;
required: boolean;
id: string;
placeholder?: string;
minRows?: number;
maxRows?: number;
options?: Option[];
tooltipText?: string;
}

interface FieldConfig {
config: IFieldInfo;
componentType: string;
form: any;
}

export interface ICertificationForm {
commonField: FieldConfig[];
auditorInfo: FieldConfig[];
auditorReport: FieldConfig[];
addScripts: { scriptFields: IInfo[]; smartContractInfo: IInfo[] };
}

const Component = (props: FieldConfig) => {
const { id, ...rest } = props.config;

switch (props.componentType) {
case "text":
return (
<Input
id={props.config.id}
{...props.form.register(props.config.id)}
{...rest}
/>
);
case "textarea":
return <TextArea {...props.form.register(props.config.id)} {...rest} />;
case "dropdown":
return (
<Dropdown
onOptionSelect={(option) =>
props.form.setValue(props.config.id, option.value, {
shouldValidate: true, // trigger on change validation manually
})
}
{...props.form.register(props.config.id)}
{...rest}
/>
);
default:
return null;
}
};
amnambiar marked this conversation as resolved.
Show resolved Hide resolved
amnambiar marked this conversation as resolved.
Show resolved Hide resolved

const CertificationForm: React.FC<{
config: ICertificationForm;
submitting: boolean;
initData: any;
form: any;
onSubmit: (data: any) => any;
onFormReset: () => void;
}> = ({ config, submitting, initData, form, onSubmit, onFormReset }) => {
const { fields, append, remove } = useFieldArray({
control: form.control,
name: fieldArrayName,
});

const addNewDappScript = () => {
append(
{
scriptHash: "",
contractAddress: "",
},
{ shouldFocus: true }
);
};

useEffect(() => {
// to be called only once initially
addNewDappScript();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const initializeFormState = () => {
form.clearErrors(); // clear form errors
form.reset(initData);
};

useEffect(() => {
initializeFormState();
// initializeFormState() is to not to be triggered on every re-render of the dep-array below but whenever the form or userDetails is updated alone
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [form]);
amnambiar marked this conversation as resolved.
Show resolved Hide resolved
amnambiar marked this conversation as resolved.
Show resolved Hide resolved

const shouldDisableAddScriptButton = useCallback(() => {
return (
!!form?.formState.errors?.[fieldArrayName] || // disable button if errors associated with dynamic form exists
form
.getValues(fieldArrayName)
?.some(
(field: { scriptHash: any; contractAddress: any }) =>
!field?.scriptHash || !field?.contractAddress
)
); // prevent addition of new script boxes if the required field is empty
}, [form]);

return (
<Form form={form} onSubmit={onSubmit}>
{config.commonField.map((field, idx) => (
<Component
form={form}
componentType={field.componentType}
config={field.config}
key={`commonField-${idx}`}
/>
))}

{config.auditorInfo.length ? (
<div className="separator-label">Auditor Information</div>
) : null}
{config.auditorInfo.map((field, idx) => (
<Component
form={form}
componentType={field.componentType}
config={field.config}
key={`auditorInfo-${idx}`}
/>
))}

{config.auditorReport.length ? (
<div className="separator-label">Audit Report</div>
) : null}
{config.auditorReport.map((field, idx) => (
<Component
form={form}
componentType={field.componentType}
config={field.config}
key={`auditorReport-${idx}`}
/>
))}

<div className="separator-label">DApp Script</div>
<div className="relative">
<div className="absolute action-button addScript-btn">
<Button
displayStyle="primary-outline"
size="small"
buttonLabel="+ Add Script"
type="button"
disabled={shouldDisableAddScriptButton()}
onClick={() => {
addNewDappScript();
}}
/>
</div>

{fields.map((field, index) => (
<DAPPScript
key={field.id}
remove={remove}
value={field}
index={index}
fieldArrayName={fieldArrayName}
config={config.addScripts}
/>
))}
</div>

<div className="button-wrapper">
<Button
type="button"
disabled={submitting}
displayStyle="secondary"
buttonLabel={"Cancel"}
onClick={onFormReset}
/>

<Button
disabled={!form.formState.isValid}
type="submit"
buttonLabel={"Submit"}
showLoader={submitting}
/>
</div>
</Form>
);
};

export default CertificationForm;
21 changes: 21 additions & 0 deletions src/components/CreateCertificate/CreateCertificate.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.certification-metadata {
.MuiDialogContent-root {
overflow-y: initial;
margin-top: 0;
padding: 16px 32px;
}

.MuiPaper-root.MuiDialog-paper {
top: 0;
max-width: 700px;
}

h2 {
font-family: inherit;
padding: 32px 32px 12px;
}

h2 button {
display: none;
}
}
Loading