-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
blockchain_integration/PiSure/client/components/InsuranceForm.js
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,50 @@ | ||
import React, { useState } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
|
||
const InsuranceForm = () => { | ||
const { register, handleSubmit, errors } = useForm(); | ||
const [policyData, setPolicyData] = useState({}); | ||
|
||
const onSubmit = async (data) => { | ||
// Call API to create new policy | ||
const response = await fetch('/api/policies', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(data), | ||
}); | ||
|
||
if (response.ok) { | ||
setPolicyData(data); | ||
} else { | ||
console.error('Error creating policy:', response.status); | ||
} | ||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<label> | ||
First Name: | ||
<input type="text" {...register('firstName')} /> | ||
</label> | ||
<label> | ||
Last Name: | ||
<input type="text" {...register('lastName')} /> | ||
</label> | ||
<label> | ||
Email: | ||
<input type="email" {...register('email')} /> | ||
</label> | ||
<label> | ||
Policy Type: | ||
<select {...register('policyType')}> | ||
<option value="health">Health</option> | ||
<option value="life">Life</option> | ||
<option value="auto">Auto</option> | ||
</select> | ||
</label> | ||
<button type="submit">Create Policy</button> | ||
</form> | ||
); | ||
}; | ||
|
||
export default InsuranceForm; |