mocksaml/pages/apps/index.tsx

82 lines
2.5 KiB
TypeScript
Raw Normal View History

2022-01-13 17:07:44 +00:00
import axios from 'axios';
import type { NextPage } from 'next';
import { ChangeEvent, FormEvent, useState } from 'react';
const Apps: NextPage = () => {
const [formData, setFormData] = useState({
2022-02-17 06:05:50 +00:00
name: null,
2022-01-13 17:50:16 +00:00
acs_url: null,
entity_id: null,
});
const [metadata, setMetadata] = useState({
sso_url: null,
entity_id: null,
certificate: null,
2022-01-13 17:07:44 +00:00
});
const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
setFormData({
...formData,
[e.target.name]: e.target.value.trim()
});
}
const createApp = async (e: FormEvent) => {
e.preventDefault();
2022-01-13 17:50:16 +00:00
const {data} = await axios.post('/api/apps', {
2022-01-13 17:07:44 +00:00
...formData
});
2022-01-13 17:50:16 +00:00
setMetadata(data);
2022-01-13 17:07:44 +00:00
};
2022-01-13 19:42:17 +00:00
const downloadMetadata = async (e: ChangeEvent<HTMLInputElement>) => {
e.preventDefault();
const {data} = await axios.post('/api/apps/metadata', {
...formData
});
}
2022-01-13 17:07:44 +00:00
return (
<div>
2022-02-17 06:05:50 +00:00
<form onSubmit={createApp} className="px-8 pt-6 pb-8 mb-4 bg-white rounded shadow-md">
2022-01-13 17:07:44 +00:00
<div className="mb-4">
2022-02-17 06:05:50 +00:00
<label className="block mb-2 text-sm">
App Name
<input type="text" name="name" onChange={handleInputChange} required className="w-full px-3 py-2 border rounded" placeholder="App Name" />
</label>
</div>
<div className="mb-4">
<label className="block mb-2 text-sm">
2022-01-13 17:07:44 +00:00
ACS URL
2022-02-17 06:05:50 +00:00
<input type="text" name="acs_url" onChange={handleInputChange} required className="w-full px-3 py-2 border rounded" placeholder="ACS URL" />
2022-01-13 17:07:44 +00:00
</label>
</div>
<div className="mb-4">
2022-02-17 06:05:50 +00:00
<label className="block mb-2 text-sm">
2022-01-13 17:07:44 +00:00
Entity ID
2022-02-17 06:05:50 +00:00
<input type="text" name="entity_id" onChange={handleInputChange} required className="w-full px-3 py-2 border rounded" placeholder="Entity ID" />
2022-01-13 17:07:44 +00:00
</label>
</div>
2022-02-17 06:05:50 +00:00
<button type="submit" className="px-4 py-2 text-white bg-blue-500 rounded">Build IdP Metadata</button>
2022-01-13 17:07:44 +00:00
</form>
2022-01-13 17:50:16 +00:00
2022-02-17 06:05:50 +00:00
<button type="button" className="px-3 py-2 text-white bg-red-500 rounded" onClick={downloadMetadata}>Download Metadata</button>
2022-01-13 19:42:17 +00:00
2022-02-17 06:05:50 +00:00
<ul className="px-8 pt-6 pb-8 mb-4 bg-white rounded shadow-md">
2022-01-13 19:20:01 +00:00
<li className="px-2 py-2"><strong>SSO URL:</strong> <br></br> {metadata.sso_url}</li>
<li className="px-2 py-2"><strong>Entity ID:</strong> <br></br> {metadata.entity_id}</li>
<li className="px-2 py-2"><strong>Certificate:</strong> <br></br> {metadata.certificate}</li>
2022-01-13 17:50:16 +00:00
</ul>
2022-01-13 17:07:44 +00:00
</div>
);
};
export default Apps;