generated from Code-the-Dream-School/react-node-practicum-front-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from Code-the-Dream-School/RegisterUserAction
register user working with backend
- Loading branch information
Showing
6 changed files
with
54 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,39 @@ | ||
import { Link } from 'react-router-dom'; | ||
import { Form, redirect, Link } from 'react-router-dom'; | ||
import styled from 'styled-components'; | ||
import { FormRow, Logo } from '../components'; | ||
import customFetch from '../util/customFetch'; | ||
|
||
//formData - is an api, gives back an array of arrays, must have name same as database | ||
export const action = async ({ request }) => { | ||
const formData = await request.formData(); | ||
// console.log(formData); | ||
const data = Object.fromEntries(formData); | ||
try { | ||
await customFetch.post('/auth/signup', data); | ||
return redirect('/login'); | ||
} catch (error) { | ||
console.log(error); | ||
return error; | ||
} | ||
}; | ||
|
||
const Register = () => { | ||
return ( | ||
<Wrapper> | ||
<form className="form"> | ||
<Form method="post" className="form"> | ||
<Logo /> | ||
<h4>Register</h4> | ||
<FormRow | ||
type="text" | ||
name="name" | ||
labelText="name" | ||
defaultValue="DefaultName" | ||
placeholder="NAME" | ||
/> | ||
<FormRow | ||
<FormRow type="text" name="name" labelText="name" placeholder="NAME" /> | ||
{/* <FormRow | ||
type="text" | ||
name="lastName" | ||
labelText="lastname" | ||
defaultValue="DefaultLastName" | ||
placeholder="LAST NAME" | ||
/> | ||
<FormRow | ||
type="text" | ||
name="store" | ||
labelText="store" | ||
defaultValue="DefaultStore" | ||
placeholder="STORE" | ||
/> | ||
<FormRow | ||
type="email" | ||
name="email" | ||
labelText="email" | ||
defaultValue="[email protected]" | ||
placeholder="EMAIL" | ||
/> | ||
/> */} | ||
<FormRow type="text" name="store" labelText="store" placeholder="STORE" /> | ||
<FormRow type="text" name="role" labelText="role" placeholder="ROLE NAME" /> | ||
<FormRow type="email" name="email" labelText="email" placeholder="EMAIL" /> | ||
<FormRow | ||
type="password" | ||
name="password" | ||
|
@@ -52,7 +50,7 @@ const Register = () => { | |
Login | ||
</Link> | ||
</p> | ||
</form> | ||
</Form> | ||
</Wrapper> | ||
); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import axios from 'axios'; | ||
|
||
const customFetch = axios.create({ | ||
baseURL: 'http://localhost:8000/api/v1', | ||
}); | ||
|
||
export default customFetch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const getFormValues = (form) => { | ||
const formData = new FormData(form); | ||
const values = [...formData.values()]; | ||
const isEmpty = values.includes(''); | ||
const data = Object.fromEntries(formData); | ||
console.log(data); | ||
return { isEmpty, data }; | ||
}; | ||
|
||
export default getFormValues; |