2022-01-13 17:07:44 +00:00
|
|
|
import axios from 'axios';
|
|
|
|
|
import type { NextPage } from 'next';
|
|
|
|
|
import { ChangeEvent, FormEvent, useState } from 'react';
|
2022-02-17 09:21:19 +00:00
|
|
|
import Router from 'next/router';
|
2022-01-13 17:07:44 +00:00
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
});
|
|
|
|
|
|
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-02-17 09:21:19 +00:00
|
|
|
const { data: app } = await axios.post('/api/apps', {
|
2022-01-13 17:07:44 +00:00
|
|
|
...formData
|
|
|
|
|
});
|
2022-01-13 17:50:16 +00:00
|
|
|
|
2022-02-17 09:21:19 +00:00
|
|
|
await Router.push(`/apps/${app.id}`);
|
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:57:50 +00:00
|
|
|
<button type="submit" className="px-4 py-2 text-white bg-blue-500 rounded">Create App</button>
|
2022-01-13 17:07:44 +00:00
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Apps;
|