Skip to content

Commit

Permalink
Create InsuranceForm.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 6, 2024
1 parent 31f0a2d commit e166d6e
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions blockchain_integration/PiSure/client/components/InsuranceForm.js
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;

0 comments on commit e166d6e

Please sign in to comment.