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

Add veteran status verification #614

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VA_API_KEY=your_api_key_here
83 changes: 83 additions & 0 deletions src/pages/VeteranStatus.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { useState } from "react";
import axios from "axios";

const VeteranStatus = () => {
const [formData, setFormData] = useState({
firstName: "",
lastName: "",
birthDate: "",
ssn: "",
});

const [response, setResponse] = useState(null);
const [error, setError] = useState(null);

const handleChange = (e) => {
const { name, value } = e.target;
setFormData({
...formData,
[name]: value,
});
};

const handleSubmit = async (e) => {
e.preventDefault();
try {
const res = await axios.post("/api/veteran-status", formData);
setResponse(res.data);
setError(null);
} catch (err) {
setError("Failed to fetch veteran status");
setResponse(null);
}
};

return (
<div>
<h1>Check Veteran Status</h1>
<form onSubmit={handleSubmit}>
<div>
<label>First Name:</label>
<input
type="text"
name="firstName"
value={formData.firstName}
onChange={handleChange}
/>
</div>
<div>
<label>Last Name:</label>
<input
type="text"
name="lastName"
value={formData.lastName}
onChange={handleChange}
/>
</div>
<div>
<label>Birth Date:</label>
<input
type="date"
name="birthDate"
value={formData.birthDate}
onChange={handleChange}
/>
</div>
<div>
<label>SSN:</label>
<input
type="text"
name="ssn"
value={formData.ssn}
onChange={handleChange}
/>
</div>
<button type="submit">Check Status</button>
</form>
{response && <div>Status: {response.status}</div>}
{error && <div>Error: {error}</div>}
</div>
);
};

export default VeteranStatus;
36 changes: 36 additions & 0 deletions src/pages/api/veteran-status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import axios from "axios";
import { NextApiRequest, NextApiResponse } from "next";

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method !== "POST") {
return res.status(405).json({ error: "Method Not Allowed" });
}

const { firstName, lastName, birthDate, ssn } = req.body;

if (!firstName || !lastName || !birthDate || !ssn) {
return res.status(400).json({ error: "Missing required fields" });
}

try {
const response = await axios.post(
"https://sandbox-api.va.gov/services/veteran-confirmation/v1/status",
{
firstName,
lastName,
birthDate,
ssn,
},
{
headers: {
"Content-Type": "application/json",
"apikey": process.env.VA_API_KEY,
},
}
);

return res.status(200).json(response.data);
} catch (error) {
return res.status(500).json({ error: "Failed to fetch veteran status" });
}
}
Loading