Add logo, login, signup form and perform login

This commit is contained in:
2020-01-07 07:59:12 +00:00
parent aeafe10f0e
commit ab750aa8ba
11 changed files with 456 additions and 9 deletions

BIN
webclient/src/.App.js.swp Normal file

Binary file not shown.

Binary file not shown.

BIN
webclient/src/.utils.js.swp Normal file

Binary file not shown.

View File

@@ -1,11 +1,142 @@
import React from 'react';
import React, { useState } from 'react';
import './light.css';
import Logo from './logo.svg';
import { Container, Divider, Form, Grid, Header, Menu, Message } from 'semantic-ui-react';
import { requester } from './utils.js';
function LoginForm() {
const [input, setInput] = useState({})
const [error, setError] = useState({})
const handleChange = (e) => setInput({
...input,
[e.currentTarget.name]: e.currentTarget.value
});
const handleSubmit = (e) => {
requester('/rest-auth/login/', 'POST', input)
.then(res => {
console.log(res);
setError({});
})
.catch(err => {
console.log(err);
setError(err.data);
});
};
return (
<Form onSubmit={handleSubmit}>
<Form.Input
label='Username'
name='username'
placeholder='first.last'
onChange={handleChange}
error={error.username}
/>
<Form.Input
label='Password'
name='password'
type='password'
onChange={handleChange}
error={error.password}
/>
<Form.Button error={error.non_field_errors}>
Login
</Form.Button>
</Form>
);
}
function SignupForm() {
const [input, setInput] = useState({})
const handleChange = (e) => setInput({
...input,
[e.currentTarget.name]: e.currentTarget.value
});
const handleSubmit = (e) => {
console.log(input);
}
return (
<Form onSubmit={handleSubmit}>
<Form.Group widths='equal'>
<Form.Input
label='First Name'
name='firstname'
onChange={handleChange}
/>
<Form.Input
label='Last Name'
name='lastname'
onChange={handleChange}
/>
</Form.Group>
<Form.Input
label='Password'
name='password1'
type='password'
onChange={handleChange}
/>
<Form.Input
label='Confirm Password'
name='password2'
type='password'
onChange={handleChange}
/>
<Form.Input
label='Email'
name='email'
onChange={handleChange}
/>
<Form.Button>Sign Up</Form.Button>
</Form>
);
}
function App() {
return (
<div>
<header>
Hello world
</header>
<Container>
<header className='header'>
<img src={Logo} className='logo' />
</header>
</Container>
<Menu>
<Container>
<Menu.Item
content='Home'
/>
<Menu.Item
content='About'
/>
<Menu.Item
content='Contact'
/>
</Container>
</Menu>
<Container>
<Grid stackable padded columns={2}>
<Grid.Column>
<Header size='medium'>Login to Spaceport</Header>
<LoginForm />
<Divider section horizontal>Or</Divider>
<Header size='medium'>Sign Up</Header>
<SignupForm />
</Grid.Column>
<Grid.Column>
<p>two</p>
</Grid.Column>
</Grid>
</Container>
</div>
);
}

5
webclient/src/light.css Normal file
View File

@@ -0,0 +1,5 @@
.header .logo {
max-width: 100%;
display: block;
margin: 1.5rem auto;
}

147
webclient/src/logo.svg Normal file
View File

@@ -0,0 +1,147 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="120.34605mm"
height="8.4772501mm"
viewBox="0 0 120.34605 8.4772501"
version="1.1"
id="svg8"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="logo.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.979899"
inkscape:cx="267.5924"
inkscape:cy="26.230935"
inkscape:document-units="mm"
inkscape:current-layer="flowRoot10"
showgrid="false"
inkscape:window-width="3840"
inkscape:window-height="2096"
inkscape:window-x="0"
inkscape:window-y="27"
inkscape:window-maximized="1"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-13.153719,-114.80657)">
<g
aria-label="PROTOSPACE PORTAL"
transform="scale(0.26458333)"
style="font-style:normal;font-weight:normal;font-size:40px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none"
id="flowRoot10">
<path
d="m 51.274844,465.5546 q -0.68,0 -1.12,-0.44 -0.44,-0.44 -0.44,-1.12 v -28.12 q 0,-0.68 0.44,-1.12 0.44,-0.44 1.12,-0.44 h 8 q 2.96,0 5.24,1.32 2.28,1.28 3.56,3.56 1.28,2.28 1.28,5.28 0,2.92 -1.28,5.2 -1.28,2.24 -3.56,3.56 -2.28,1.28 -5.24,1.28 h -6.44 v 9.48 q 0,0.68 -0.44,1.12 -0.44,0.44 -1.12,0.44 z m 1.56,-14.04 h 6.44 q 2.04,0 3.64,-0.88 1.6,-0.92 2.48,-2.52 0.92,-1.6 0.92,-3.64 0,-2.12 -0.92,-3.72 -0.88,-1.6 -2.48,-2.52 -1.6,-0.92 -3.64,-0.92 h -6.44 z"
style="fill:#999999"
id="path24"
inkscape:connector-curvature="0" />
<path
d="m 75.727969,465.5546 q -0.68,0 -1.12,-0.44 -0.44,-0.44 -0.44,-1.12 v -28.12 q 0,-0.68 0.44,-1.12 0.44,-0.44 1.12,-0.44 h 7.48 q 2.92,0 5.2,1.24 2.28,1.2 3.56,3.4 1.32,2.16 1.32,5 0,2.72 -1.32,4.84 -1.28,2.12 -3.56,3.32 -2.28,1.2 -5.2,1.2 h -5.92 v 10.68 q 0,0.68 -0.44,1.12 -0.44,0.44 -1.12,0.44 z m 16.72,0 q -0.52,0 -0.84,-0.2 -0.28,-0.2 -0.52,-0.6 l -7.68,-12.24 3.12,-0.8 7.16,11.44 q 0.6,0.96 0.2,1.68 -0.36,0.72 -1.44,0.72 z m -15.16,-15.24 h 5.92 q 2.04,0 3.6,-0.8 1.6,-0.84 2.52,-2.28 0.92,-1.44 0.92,-3.28 0,-1.96 -0.92,-3.44 -0.92,-1.52 -2.52,-2.36 -1.56,-0.84 -3.6,-0.84 h -5.92 z"
style="fill:#999999"
id="path26"
inkscape:connector-curvature="0" />
<path
d="m 113.29547,465.9546 q -3.48,0 -6.4,-1.2 -2.92,-1.2 -5.08,-3.36 -2.120001,-2.16 -3.320001,-5.08 -1.16,-2.92 -1.16,-6.4 0,-3.44 1.16,-6.36 1.2,-2.92 3.320001,-5.08 2.16,-2.16 5.08,-3.36 2.92,-1.2 6.4,-1.2 3.44,0 6.36,1.2 2.92,1.2 5.08,3.36 2.16,2.16 3.32,5.08 1.2,2.92 1.2,6.36 0,3.48 -1.2,6.4 -1.16,2.92 -3.32,5.08 -2.16,2.16 -5.08,3.36 -2.92,1.2 -6.36,1.2 z m 0,-2.96 q 2.76,0 5.12,-0.96 2.36,-1 4.08,-2.76 1.76,-1.8 2.72,-4.16 0.96,-2.4 0.96,-5.2 0,-2.76 -0.96,-5.12 -0.96,-2.4 -2.72,-4.16 -1.72,-1.8 -4.08,-2.76 -2.36,-1 -5.12,-1 -2.8,0 -5.16,1 -2.36,0.96 -4.12,2.76 -1.72,1.76 -2.68,4.16 -0.96,2.36 -0.96,5.12 0,2.8 0.96,5.2 0.96,2.36 2.68,4.16 1.76,1.76 4.12,2.76 2.36,0.96 5.16,0.96 z"
style="fill:#999999"
id="path28"
inkscape:connector-curvature="0" />
<path
d="m 142.38859,465.5546 q -0.64,0 -1.12,-0.44 -0.44,-0.48 -0.44,-1.12 v -29.68 h 3.12 v 29.68 q 0,0.64 -0.44,1.12 -0.44,0.44 -1.12,0.44 z m -11.04,-28.4 q -0.64,0 -1.04,-0.4 -0.4,-0.4 -0.4,-1 0,-0.64 0.4,-1.04 0.4,-0.4 1.04,-0.4 h 22.12 q 0.64,0 1.04,0.4 0.4,0.4 0.4,1.04 0,0.6 -0.4,1 -0.4,0.4 -1.04,0.4 z"
style="fill:#999999"
id="path30"
inkscape:connector-curvature="0" />
<path
d="m 171.88922,465.9546 q -3.48,0 -6.4,-1.2 -2.92,-1.2 -5.08,-3.36 -2.12,-2.16 -3.32,-5.08 -1.16,-2.92 -1.16,-6.4 0,-3.44 1.16,-6.36 1.2,-2.92 3.32,-5.08 2.16,-2.16 5.08,-3.36 2.92,-1.2 6.4,-1.2 3.44,0 6.36,1.2 2.92,1.2 5.08,3.36 2.16,2.16 3.32,5.08 1.2,2.92 1.2,6.36 0,3.48 -1.2,6.4 -1.16,2.92 -3.32,5.08 -2.16,2.16 -5.08,3.36 -2.92,1.2 -6.36,1.2 z m 0,-2.96 q 2.76,0 5.12,-0.96 2.36,-1 4.08,-2.76 1.76,-1.8 2.72,-4.16 0.96,-2.4 0.96,-5.2 0,-2.76 -0.96,-5.12 -0.96,-2.4 -2.72,-4.16 -1.72,-1.8 -4.08,-2.76 -2.36,-1 -5.12,-1 -2.8,0 -5.16,1 -2.36,0.96 -4.12,2.76 -1.72,1.76 -2.68,4.16 -0.96,2.36 -0.96,5.12 0,2.8 0.96,5.2 0.96,2.36 2.68,4.16 1.76,1.76 4.12,2.76 2.36,0.96 5.16,0.96 z"
style="fill:#999999"
id="path32"
inkscape:connector-curvature="0" />
<path
d="m 204.12422,465.9546 q -2.56,0 -4.84,-0.76 -2.24,-0.8 -3.92,-2.2 -1.68,-1.44 -2.52,-3.28 -0.36,-0.76 0,-1.4 0.4,-0.68 1.32,-0.88 0.64,-0.16 1.28,0.2 0.68,0.32 1,1 0.52,1.08 1.64,1.96 1.12,0.84 2.68,1.36 1.6,0.52 3.36,0.52 2,0 3.6,-0.64 1.64,-0.64 2.6,-1.84 1,-1.2 1,-2.96 0,-2.24 -1.72,-3.92 -1.68,-1.72 -5.48,-2.16 -4.88,-0.52 -7.68,-2.92 -2.76,-2.4 -2.76,-5.92 0,-2.6 1.4,-4.4 1.44,-1.84 3.88,-2.8 2.48,-0.96 5.56,-0.96 2.36,0 4.16,0.68 1.8,0.68 3.16,1.88 1.36,1.16 2.32,2.72 0.48,0.8 0.36,1.52 -0.08,0.72 -0.72,1.12 -0.72,0.4 -1.52,0.16 -0.8,-0.28 -1.2,-0.96 -0.6,-1.08 -1.52,-1.88 -0.92,-0.8 -2.2,-1.28 -1.24,-0.48 -2.96,-0.48 -3,-0.04 -5,1.2 -1.96,1.2 -1.96,3.6 0,1.28 0.64,2.4 0.68,1.08 2.32,1.92 1.68,0.8 4.68,1.12 4.84,0.56 7.4,2.96 2.6,2.4 2.6,6.28 0,2.24 -0.88,3.92 -0.88,1.68 -2.44,2.84 -1.52,1.12 -3.52,1.72 -1.96,0.56 -4.12,0.56 z"
style="font-style:normal;font-variant:normal;font-weight:600;font-stretch:normal;font-family:Comfortaa;-inkscape-font-specification:'Comfortaa Semi-Bold'"
id="path34"
inkscape:connector-curvature="0" />
<path
d="m 223.43172,465.5546 q -0.84,0 -1.4,-0.52 -0.52,-0.56 -0.52,-1.4 v -27.4 q 0,-0.84 0.52,-1.36 0.56,-0.56 1.4,-0.56 h 8 q 2.96,0 5.28,1.32 2.32,1.32 3.6,3.64 1.28,2.28 1.28,5.32 0,2.96 -1.28,5.24 -1.28,2.24 -3.6,3.52 -2.32,1.28 -5.28,1.28 h -6.12 v 9 q 0,0.84 -0.52,1.4 -0.52,0.52 -1.36,0.52 z m 1.88,-14.48 h 6.12 q 1.88,0 3.36,-0.8 1.48,-0.84 2.28,-2.32 0.84,-1.48 0.84,-3.36 0,-2 -0.84,-3.48 -0.8,-1.52 -2.28,-2.36 -1.48,-0.88 -3.36,-0.88 h -6.12 z"
style="font-style:normal;font-variant:normal;font-weight:600;font-stretch:normal;font-family:Comfortaa;-inkscape-font-specification:'Comfortaa Semi-Bold'"
id="path36"
inkscape:connector-curvature="0" />
<path
d="m 243.70547,465.5546 q -1.04,0 -1.6,-0.88 -0.52,-0.92 -0.08,-1.88 l 11.4,-27.2 q 0.56,-1.28 1.8,-1.28 1.32,0 1.8,1.28 l 11.48,27.28 q 0.4,1 -0.16,1.84 -0.52,0.84 -1.56,0.84 -0.56,0 -1.08,-0.28 -0.48,-0.32 -0.72,-0.88 l -10.28,-25.32 h 1.16 l -10.4,25.32 q -0.24,0.56 -0.76,0.88 -0.48,0.28 -1,0.28 z m 2.28,-7.08 1.48,-3.16 h 15.88 l 1.44,3.16 z"
style="font-style:normal;font-variant:normal;font-weight:600;font-stretch:normal;font-family:Comfortaa;-inkscape-font-specification:'Comfortaa Semi-Bold'"
id="path38"
inkscape:connector-curvature="0" />
<path
d="m 286.44922,465.9546 q -3.24,0 -6.08,-1.2 -2.8,-1.24 -4.92,-3.44 -2.08,-2.2 -3.28,-5.12 -1.2,-2.92 -1.2,-6.28 0,-3.32 1.16,-6.2 1.2,-2.92 3.32,-5.12 2.12,-2.2 4.92,-3.44 2.8,-1.24 6.08,-1.24 3.04,0 5.28,0.84 2.28,0.8 4.52,2.64 0.32,0.24 0.44,0.56 0.16,0.28 0.12,0.56 0,0.28 -0.08,0.6 -0.04,0.6 -0.52,1 -0.44,0.36 -1.12,0.4 -0.64,0.04 -1.24,-0.44 -1.52,-1.32 -3.2,-2 -1.64,-0.68 -4.2,-0.68 -2.44,0 -4.6,1 -2.12,1 -3.76,2.72 -1.6,1.72 -2.52,4 -0.92,2.24 -0.92,4.8 0,2.6 0.92,4.88 0.92,2.28 2.52,4 1.64,1.72 3.76,2.68 2.16,0.96 4.6,0.96 2.12,0 3.96,-0.68 1.88,-0.72 3.6,-2 0.64,-0.48 1.28,-0.4 0.64,0.04 1.08,0.52 0.48,0.44 0.48,1.24 0,0.4 -0.16,0.76 -0.12,0.32 -0.44,0.6 -2.12,1.8 -4.6,2.64 -2.48,0.84 -5.2,0.84 z"
style="font-style:normal;font-variant:normal;font-weight:600;font-stretch:normal;font-family:Comfortaa;-inkscape-font-specification:'Comfortaa Semi-Bold'"
id="path40"
inkscape:connector-curvature="0" />
<path
d="m 305.38484,465.5546 q -0.84,0 -1.4,-0.52 -0.52,-0.56 -0.52,-1.4 v -27.4 q 0,-0.84 0.52,-1.36 0.56,-0.56 1.4,-0.56 h 18.28 q 0.84,0 1.36,0.52 0.52,0.48 0.52,1.28 0,0.76 -0.52,1.28 -0.52,0.48 -1.36,0.48 h -16.4 v 10.16 h 11.84 q 0.84,0 1.36,0.52 0.52,0.48 0.52,1.28 0,0.76 -0.52,1.28 -0.52,0.48 -1.36,0.48 h -11.84 v 10.4 h 16.4 q 0.84,0 1.36,0.52 0.52,0.48 0.52,1.24 0,0.8 -0.52,1.32 -0.52,0.48 -1.36,0.48 z"
style="font-style:normal;font-variant:normal;font-weight:600;font-stretch:normal;font-family:Comfortaa;-inkscape-font-specification:'Comfortaa Semi-Bold'"
id="path42"
inkscape:connector-curvature="0" />
<path
d="m 344.99422,465.5546 q -0.84,0 -1.4,-0.52 -0.52,-0.56 -0.52,-1.4 v -27.4 q 0,-0.84 0.52,-1.36 0.56,-0.56 1.4,-0.56 h 8 q 2.96,0 5.28,1.32 2.32,1.32 3.6,3.64 1.28,2.28 1.28,5.32 0,2.96 -1.28,5.24 -1.28,2.24 -3.6,3.52 -2.32,1.28 -5.28,1.28 h -6.12 v 9 q 0,0.84 -0.52,1.4 -0.52,0.52 -1.36,0.52 z m 1.88,-14.48 h 6.12 q 1.88,0 3.36,-0.8 1.48,-0.84 2.28,-2.32 0.84,-1.48 0.84,-3.36 0,-2 -0.84,-3.48 -0.8,-1.52 -2.28,-2.36 -1.48,-0.88 -3.36,-0.88 h -6.12 z"
style="font-style:normal;font-variant:normal;font-weight:600;font-stretch:normal;font-family:Comfortaa;-inkscape-font-specification:'Comfortaa Semi-Bold'"
id="path44"
inkscape:connector-curvature="0" />
<path
d="m 382.27984,465.9546 q -3.52,0 -6.44,-1.16 -2.92,-1.2 -5.04,-3.36 -2.08,-2.16 -3.28,-5.08 -1.16,-2.92 -1.16,-6.44 0,-3.48 1.16,-6.4 1.2,-2.92 3.28,-5.08 2.12,-2.16 5.04,-3.32 2.92,-1.2 6.44,-1.2 3.48,0 6.4,1.2 2.92,1.16 5.04,3.32 2.12,2.16 3.28,5.08 1.2,2.92 1.2,6.4 0,3.52 -1.2,6.44 -1.16,2.92 -3.28,5.08 -2.12,2.16 -5.04,3.36 -2.92,1.16 -6.4,1.16 z m 0,-3.48 q 2.64,0 4.88,-0.96 2.24,-0.96 3.88,-2.64 1.68,-1.72 2.56,-4 0.88,-2.28 0.88,-4.96 0,-2.64 -0.88,-4.92 -0.88,-2.32 -2.56,-4 -1.64,-1.72 -3.88,-2.64 -2.24,-0.96 -4.88,-0.96 -2.68,0 -4.92,0.96 -2.24,0.92 -3.88,2.64 -1.6,1.68 -2.52,4 -0.92,2.28 -0.92,4.92 0,2.68 0.92,4.96 0.92,2.28 2.52,4 1.64,1.68 3.88,2.64 2.24,0.96 4.92,0.96 z"
style="font-style:normal;font-variant:normal;font-weight:600;font-stretch:normal;font-family:Comfortaa;-inkscape-font-specification:'Comfortaa Semi-Bold'"
id="path46"
inkscape:connector-curvature="0" />
<path
d="m 406.63484,465.5546 q -0.84,0 -1.4,-0.52 -0.52,-0.56 -0.52,-1.4 v -27.4 q 0,-0.84 0.52,-1.36 0.56,-0.56 1.4,-0.56 h 7.28 q 2.96,0 5.28,1.24 2.32,1.24 3.6,3.44 1.32,2.2 1.32,5.08 0,2.72 -1.32,4.84 -1.28,2.12 -3.6,3.32 -2.32,1.2 -5.28,1.2 h -5.4 v 10.2 q 0,0.84 -0.52,1.4 -0.52,0.52 -1.36,0.52 z m 16.64,0 q -0.56,0 -0.96,-0.2 -0.4,-0.24 -0.72,-0.72 l -7.36,-11.84 3.76,-1.04 6.76,10.88 q 0.68,1.08 0.2,2 -0.48,0.92 -1.68,0.92 z m -14.76,-15.68 h 5.4 q 1.92,0 3.36,-0.72 1.48,-0.76 2.32,-2.08 0.84,-1.32 0.84,-3 0,-1.8 -0.84,-3.2 -0.84,-1.44 -2.32,-2.2 -1.44,-0.8 -3.36,-0.8 h -5.4 z"
style="font-style:normal;font-variant:normal;font-weight:600;font-stretch:normal;font-family:Comfortaa;-inkscape-font-specification:'Comfortaa Semi-Bold'"
id="path48"
inkscape:connector-curvature="0" />
<path
d="m 438.95297,465.5546 q -0.76,0 -1.32,-0.56 -0.56,-0.56 -0.56,-1.36 v -29.32 h 3.8 v 29.32 q 0,0.8 -0.56,1.36 -0.52,0.56 -1.36,0.56 z m -10.8,-27.72 q -0.8,0 -1.28,-0.48 -0.48,-0.52 -0.48,-1.28 0,-0.8 0.48,-1.28 0.48,-0.48 1.28,-0.48 h 21.64 q 0.8,0 1.28,0.48 0.48,0.48 0.48,1.28 0,0.76 -0.48,1.28 -0.48,0.48 -1.28,0.48 z"
style="font-style:normal;font-variant:normal;font-weight:600;font-stretch:normal;font-family:Comfortaa;-inkscape-font-specification:'Comfortaa Semi-Bold'"
id="path50"
inkscape:connector-curvature="0" />
<path
d="m 454.40109,465.5546 q -0.92,0 -1.32,-0.76 -0.4,-0.76 -0.08,-1.48 l 11.76,-27.92 q 0.44,-1.08 1.52,-1.08 1.04,0 1.48,1.08 l 11.8,27.96 q 0.36,0.76 -0.12,1.48 -0.44,0.72 -1.28,0.72 -0.48,0 -0.88,-0.24 -0.36,-0.24 -0.6,-0.72 l -11,-26.68 h 1.24 l -11.08,26.68 q -0.2,0.48 -0.6,0.72 -0.36,0.24 -0.84,0.24 z m 2.64,-7.44 1.2,-2.68 h 16.24 l 1.2,2.68 z"
style="fill:#999999"
id="path52"
inkscape:connector-curvature="0" />
<path
d="m 485.80609,465.5546 q -0.64,0 -1.12,-0.44 -0.44,-0.44 -0.44,-1.12 v -28.12 q 0,-0.64 0.44,-1.08 0.48,-0.48 1.12,-0.48 0.64,0 1.08,0.48 0.48,0.44 0.48,1.08 v 26.72 h 15.64 q 0.64,0 1.08,0.44 0.48,0.4 0.48,1.04 0,0.64 -0.48,1.08 -0.44,0.4 -1.08,0.4 z"
style="fill:#999999"
id="path54"
inkscape:connector-curvature="0" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 13 KiB

56
webclient/src/utils.js Normal file
View File

@@ -0,0 +1,56 @@
var siteUrl, apiUrl;
if (process.env.NODE_ENV !== 'production') {
siteUrl = 'http://spaceport.dns.t0.vc';
apiUrl = 'http://spaceport-api.dns.t0.vc';
} else {
siteUrl = 'https://' + window.location.hostname;
apiUrl = 'https://api.' + window.location.hostname;
}
export const requester = (route, method, data) => {
var options;
if (method == 'GET') {
options = {};
} else if (method == 'POST') {
const formData = new FormData();
Object.keys(data).forEach(key =>
formData.append(key, data[key])
);
options = {
method: 'POST',
body: formData,
};
} else {
return 'Method not supported';
}
const customError = (data) => {
const error = new Error(JSON.stringify(data));
error.data = data;
return error;
}
return fetch(apiUrl + route, options)
.then(response => {
if (!response.ok) {
throw customError(response);
}
return response.json();
})
.catch(error => {
const code = error.data.status;
if (code == 413) {
throw customError({non_field_errors: ['File too big']});
} else if (code == 400) {
return error.data.json()
.then(result => {
throw customError(result);
});
} else {
throw customError({non_field_errors: ['Network Error']});
}
});
}