Skip to content

Commit

Permalink
Merge pull request #33 from Code-the-Dream-School/RegisterUserAction
Browse files Browse the repository at this point in the history
register user working with backend
  • Loading branch information
GinaCastromonte authored Dec 12, 2024
2 parents d1828f4 + 14c4ced commit 4899e10
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 36 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@chakra-ui/react": "^3.2.1",
"@emotion/react": "^11.13.5",
"@emotion/styled": "^11.13.5",
"axios": "^1.6.7",
"axios": "^1.3.6",
"framer-motion": "^6.5.1",
"node": "^22.12.0",
"react": "^18.2.0",
Expand Down
3 changes: 3 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
Alarms,
} from './pages';

import { action as registerAction } from './pages/Register';

const router = createBrowserRouter([
{
path: '/',
Expand All @@ -34,6 +36,7 @@ const router = createBrowserRouter([
{
path: 'register',
element: <Register />,
action: registerAction,
},
{
path: 'login',
Expand Down
50 changes: 24 additions & 26 deletions src/pages/Register.jsx
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"
Expand All @@ -52,7 +50,7 @@ const Register = () => {
Login
</Link>
</p>
</form>
</Form>
</Wrapper>
);
};
Expand Down
7 changes: 7 additions & 0 deletions src/util/customFetch.js
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;
10 changes: 10 additions & 0 deletions src/util/getFormValues.js
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;

0 comments on commit 4899e10

Please sign in to comment.