Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register user working with backend #33

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 16 additions & 23 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",
"react": "^18.2.0",
"react-dom": "^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;
Loading