add fetch

This commit is contained in:
kevmodrome 2020-05-27 11:44:15 +02:00
parent a028e2e3aa
commit b2d2c25bd1
4 changed files with 33 additions and 9 deletions

View File

@ -2,6 +2,8 @@
import Button from "components/common/Button.svelte" import Button from "components/common/Button.svelte"
export let name, description =`A minimalist CRM which removes the noise and allows you to focus export let name, description =`A minimalist CRM which removes the noise and allows you to focus
on your business.`, _id; on your business.`, _id;
</script> </script>
<div class="apps-card"> <div class="apps-card">

View File

@ -26,8 +26,9 @@
<style> <style>
.apps { .apps {
display: grid; display: grid;
grid-template-columns: repeat(auto-fit, minmax(400, 1fr)); grid-template-columns: repeat(auto-fill, 400px);
gap: 85px; grid-gap: 40px 85px;
justify-content: start;
} }
.root { .root {
margin: 40px 80px; margin: 40px 80px;

View File

@ -7,6 +7,27 @@
const { close } = getContext("simple-modal") const { close } = getContext("simple-modal")
let name = ""
let description = ""
const createNewApp = async () => {
const data = { name, description}
try {
const response = await fetch('/api/applications', {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json'
// 'Content-Type': 'application/x-www-form-urlencoded',
},
body: JSON.stringify(data) // body data type must match "Content-Type" header
});
} catch (error) {
}
}
let value let value
let onChange = () => {} let onChange = () => {}
@ -15,12 +36,10 @@
close() close()
} }
function _onOkay() { async function _onOkay() {
onOkay(value) await createNewApp()
close() close()
} }
$: onChange(value)
</script> </script>
<div class="container"> <div class="container">
@ -29,8 +48,9 @@
<span class="icon"><AppsIcon /></span> <span class="icon"><AppsIcon /></span>
<h3>Create new web app</h3> <h3>Create new web app</h3>
</div> </div>
<Input name="name" label="Name" placeholder="Enter application name" /> <Input name="name" label="Name" placeholder="Enter application name" on:change={(e) => name = e.target.value} on:input={(e) => name = e.target.value} />
<TextArea <TextArea
bind:value={description}
name="description" name="description"
label="Description" label="Description"
placeholder="Describe your application" /> placeholder="Describe your application" />

View File

@ -20,6 +20,7 @@
await store.setPackage(pkg) await store.setPackage(pkg)
return pkg return pkg
} else { } else {
console.log(pkg)
throw new Error(pkg) throw new Error(pkg)
} }
} }