add Site creating
Signed-off-by: garionion <github@entr0py.de>
This commit is contained in:
parent
104d785d51
commit
b8bbfff381
3 changed files with 51 additions and 9 deletions
|
@ -99,5 +99,5 @@ export async function getSites(): Promise<Site[]> {
|
|||
}
|
||||
|
||||
export async function createSite(site: Site) {
|
||||
return request<cSite>("/sites", { auth: true, method: HTTPMethod.POST });
|
||||
return request<cSite>("/sites", { auth: true, method: HTTPMethod.POST }, site);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ export interface LoginResponse {
|
|||
|
||||
export interface Site {
|
||||
default_prefix: string;
|
||||
id: number;
|
||||
id?: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,29 +35,71 @@
|
|||
class="dark:text-white container mx-auto h-full flex justify-center items-center mt-12"
|
||||
>
|
||||
<h1 class="font-hairline mb-6 text-center">New Site</h1>
|
||||
<form>
|
||||
<form @submit.prevent="createSite">
|
||||
<label
|
||||
>Name
|
||||
<input type="text" placeholder="Name" />
|
||||
<input
|
||||
type="text"
|
||||
class="text-black"
|
||||
v-model="newSiteName"
|
||||
placeholder="Name"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Default Prefix
|
||||
<input type="text" placeholder="Default Prefix" />
|
||||
<input
|
||||
type="text"
|
||||
class="text-black"
|
||||
v-model="newDefaultPrefix"
|
||||
placeholder="Default Prefix"
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
class="bg-green-600 hover:bg-green-400 text-white font-bold py-2 px-4 rounded"
|
||||
type="submit"
|
||||
>
|
||||
Create!
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { getSites, Site } from "../api";
|
||||
import {
|
||||
getSites as apiGetSites,
|
||||
Site,
|
||||
createSite as apiCreateSite,
|
||||
} from "../api";
|
||||
import { ref } from "vue";
|
||||
|
||||
export default {
|
||||
name: "Sites",
|
||||
setup() {
|
||||
async setup() {
|
||||
const sites = ref<Site[]>([]);
|
||||
getSites().then((s) => void (sites.value = s));
|
||||
return { sites };
|
||||
async function getSites() {
|
||||
apiGetSites().then((s) => void (sites.value = s));
|
||||
}
|
||||
await getSites();
|
||||
|
||||
const newSiteName = ref("");
|
||||
const newDefaultPrefix = ref("");
|
||||
async function createSite() {
|
||||
try {
|
||||
const site: Site = {
|
||||
name: newSiteName.value,
|
||||
default_prefix: newDefaultPrefix.value,
|
||||
};
|
||||
let newSite = await apiCreateSite(site);
|
||||
console.log(newSite);
|
||||
await getSites();
|
||||
newSiteName.value = ""
|
||||
newDefaultPrefix.value = ""
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
return { sites, newSiteName, newDefaultPrefix, createSite };
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue