forked from UnlockedLabs/UnlockEdv2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7472676
commit abdeba0
Showing
6 changed files
with
693 additions
and
252 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
70 changes: 70 additions & 0 deletions
70
frontend/src/Components/forms/AddResourceCollectionForm.tsx
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,70 @@ | ||
import { useState } from 'react'; | ||
import { useForm, SubmitHandler } from 'react-hook-form'; | ||
import { TextInput, CloseX, SubmitButton } from '../inputs'; | ||
|
||
type Inputs = { | ||
collectionName: string; | ||
linkName: string; | ||
linkUrl: string; | ||
}; | ||
|
||
interface AddResourceCollectionFormProps { | ||
onSuccess: ( | ||
collectionName: string, | ||
linkName: string, | ||
linkUrl: string | ||
) => void; | ||
} | ||
|
||
export default function AddResourceCollectionForm({ | ||
onSuccess | ||
}: AddResourceCollectionFormProps) { | ||
const [errorMessage, _] = useState(''); | ||
const { | ||
register, | ||
handleSubmit, | ||
reset, | ||
formState: { errors } | ||
} = useForm<Inputs>(); | ||
|
||
const onSubmit: SubmitHandler<Inputs> = async (data) => { | ||
onSuccess(data.collectionName, data.linkName, data.linkUrl); | ||
reset(); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<CloseX close={() => reset()} /> | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<TextInput | ||
label="Collection Name" | ||
interfaceRef="collectionName" | ||
required={true} | ||
length={25} | ||
errors={errors} | ||
register={register} | ||
/> | ||
<p className="text-sm text-red-500 mt-2"> | ||
To add a collection, you must also add an accompanying link. | ||
</p> | ||
<TextInput | ||
label="Link Name" | ||
interfaceRef="linkName" | ||
required={true} | ||
length={25} | ||
errors={errors} | ||
register={register} | ||
/> | ||
<TextInput | ||
label="Link URL" | ||
interfaceRef="linkUrl" | ||
required={true} | ||
length={null} | ||
errors={errors} | ||
register={register} | ||
/> | ||
<SubmitButton errorMessage={errorMessage} /> | ||
</form> | ||
</div> | ||
); | ||
} |
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.