-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webform): new ABP11 form and updated Upload component (#360)
* fix: change Upload to follow other form Input management standard * feat: add Upload to slots - also remove unused import * feat: add new abp form * fix: verbiage update for abp * fix: set initializer for upload * fix: allow ref pass in to be used at some point * spell check * fix: wf location and file upload changes --------- Co-authored-by: Benjamin Paige <[email protected]>
- Loading branch information
1 parent
6233cf7
commit 7547805
Showing
18 changed files
with
157 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./v202401"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { FormSchema } from "shared-types"; | ||
|
||
export const v202401: FormSchema = { | ||
header: "ABP 11: Payment methodology", | ||
sections: [ | ||
{ | ||
title: "Alternative Benefit Plans - Payment methodologies", | ||
form: [ | ||
{ | ||
slots: [ | ||
{ | ||
rhf: "Checkbox", | ||
name: "economy_and_efficiency_of_plans", | ||
rules: { required: "* Required" }, | ||
props: { | ||
options: [ | ||
{ | ||
label: | ||
"The state or territory provides assurance that, for each benefit provided under an Alternative Benefit Plan that is not provided through managed care, it will use the payment methodology in its approved state plan or hereby submits state plan amendment Attachment 4.19a, 4.19b, or 4.19d, as appropriate, describing the payment methodology for the benefit.", | ||
value: "assures_alternative_benefit_plan_in_accordance", | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
rhf: "Upload", | ||
name: "state_plan_attchmnt_alt_payment_method", | ||
label: "State plan amendment attachment", | ||
labelStyling: "font-bold", | ||
description: | ||
"Only required if not using the payment methodology in the approved state plan", | ||
descriptionAbove: true, | ||
props: { maxFiles: 3 }, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,93 @@ | ||
import { cn } from "@/lib"; | ||
import { useCallback, useState } from "react"; | ||
import { useCallback, useState, forwardRef } from "react"; | ||
import { useDropzone, FileRejection, Accept } from "react-dropzone"; | ||
import * as I from "@/components/Inputs"; | ||
import { X } from "lucide-react"; | ||
import { FILE_TYPES } from "shared-types/uploads"; | ||
|
||
type UploadProps = { | ||
maxFiles?: number; | ||
files: File[]; | ||
setFiles: (files: File[]) => void; | ||
value?: File[]; | ||
onChange: (files: File[]) => void; | ||
setError?: (e: string) => void; | ||
}; | ||
|
||
export const Upload = ({ maxFiles, files, setFiles }: UploadProps) => { | ||
const [errorMessage, setErrorMessage] = useState<string | null>(null); | ||
export const Upload = forwardRef<HTMLInputElement, UploadProps>( | ||
({ maxFiles, value = [], onChange, setError }, _ref) => { | ||
const [errorMessage, setErrorMessage] = useState<string | null>(null); | ||
|
||
const onDrop = useCallback( | ||
(acceptedFiles: File[], fileRejections: FileRejection[]) => { | ||
if (fileRejections.length > 0) { | ||
setErrorMessage( | ||
"Selected file(s) is too large or of a disallowed file type." | ||
); | ||
} else { | ||
setErrorMessage(null); | ||
setFiles([...files, ...acceptedFiles]); | ||
} | ||
}, | ||
[files] | ||
); | ||
const onDrop = useCallback( | ||
(acceptedFiles: File[], fileRejections: FileRejection[]) => { | ||
if (fileRejections.length > 0) { | ||
const errormsg = | ||
"Selected file(s) is too large or of a disallowed file type."; | ||
setError ? setError(errormsg) : setErrorMessage(errormsg); | ||
} else { | ||
setErrorMessage(null); | ||
onChange([...value, ...acceptedFiles]); | ||
} | ||
}, | ||
[value] | ||
); | ||
|
||
const accept: Accept = {}; | ||
FILE_TYPES.map((type) => | ||
accept[type.mime] | ||
? accept[type.mime].push(type.extension) | ||
: (accept[type.mime] = [type.extension]) | ||
); | ||
const accept: Accept = {}; | ||
FILE_TYPES.map((type) => | ||
accept[type.mime] | ||
? accept[type.mime].push(type.extension) | ||
: (accept[type.mime] = [type.extension]) | ||
); | ||
|
||
const { getRootProps, getInputProps, isDragActive } = useDropzone({ | ||
onDrop, | ||
accept, | ||
maxFiles, | ||
maxSize: 80 * 1024 * 1024, // 80MB, | ||
}); | ||
const { getRootProps, getInputProps, isDragActive } = useDropzone({ | ||
onDrop, | ||
accept, | ||
maxFiles, | ||
maxSize: 80 * 1024 * 1024, // 80MB, | ||
}); | ||
|
||
return ( | ||
<> | ||
<div className="my-2 flex gap-2"> | ||
{files.map((file) => ( | ||
// <div key={file.name} className="my-2 flex gap-2"> | ||
<div | ||
className="flex border-2 rounded-md py-1 pl-2.5 pr-1 border-sky-500 items-center" | ||
key={file.name} | ||
> | ||
<span className="text-sky-700">{file.name}</span> | ||
<I.Button | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
setFiles(files.filter((a) => a.name !== file.name)); | ||
}} | ||
variant="ghost" | ||
className="p-0 h-0" | ||
return ( | ||
<> | ||
<div className="my-2 flex gap-2"> | ||
{value?.map((file) => ( | ||
// <div key={file.name} className="my-2 flex gap-2"> | ||
<div | ||
className="flex border-2 rounded-md py-1 pl-2.5 pr-1 border-sky-500 items-center" | ||
key={file.name} | ||
> | ||
<X className="ml-2 text-sky-700 w-5" /> | ||
</I.Button> | ||
{/* </div> */} | ||
</div> | ||
))} | ||
</div> | ||
{errorMessage && <span className="text-red-500">{errorMessage}</span>} | ||
<div | ||
{...getRootProps()} | ||
className={cn( | ||
"w-full flex items-center justify-center border border-dashed py-6 rounded-sm", | ||
isDragActive && "border-blue-700" | ||
)} | ||
> | ||
<p> | ||
Drag file here or{" "} | ||
<span className="text-sky-700 underline hover:cursor-pointer"> | ||
choose from folder | ||
</span> | ||
</p> | ||
<input {...getInputProps()} /> | ||
{/* {isDragActive && <p>Drag is Active</p>} */} | ||
</div> | ||
</> | ||
); | ||
}; | ||
<span className="text-sky-700">{file.name}</span> | ||
<I.Button | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
onChange(value?.filter((a) => a.name !== file.name)); | ||
}} | ||
variant="ghost" | ||
className="p-0 h-0" | ||
> | ||
<X className="ml-2 text-sky-700 w-5" /> | ||
</I.Button> | ||
{/* </div> */} | ||
</div> | ||
))} | ||
</div> | ||
{errorMessage && <span className="text-red-500">{errorMessage}</span>} | ||
<div | ||
{...getRootProps()} | ||
className={cn( | ||
"w-full flex items-center justify-center border border-dashed py-6 rounded-sm", | ||
isDragActive && "border-blue-700" | ||
)} | ||
> | ||
<p> | ||
Drag file here or{" "} | ||
<span className="text-sky-700 underline hover:cursor-pointer"> | ||
choose from folder | ||
</span> | ||
</p> | ||
<input {...getInputProps()} /> | ||
{/* {isDragActive && <p>Drag is Active</p>} */} | ||
</div> | ||
</> | ||
); | ||
} | ||
); | ||
|
||
Upload.displayName = "Upload"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.