-
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.
- Loading branch information
1 parent
c1de209
commit 2dec133
Showing
15 changed files
with
236 additions
and
81 deletions.
There are no files selected for viewing
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 +1,2 @@ | ||
GATSBY_PATH_PREFIX=/impresso-datalab | ||
GATSBY_PATH_PREFIX=/impresso-datalab | ||
GATSBY_IMPRESSO_API_URL=http://localhost:8000/api |
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
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,34 +1,86 @@ | ||
import React from 'react' | ||
import ModalView from './ModalView' | ||
import { ModalLoginView } from '../store' | ||
import { Button, Form, Modal } from 'react-bootstrap' | ||
import React, { useRef } from "react" | ||
import ModalView from "./ModalView" | ||
import { ModalLoginView } from "../store" | ||
import { Button, Form, Modal } from "react-bootstrap" | ||
import { useMutation } from "@tanstack/react-query" | ||
import axios from "axios" | ||
|
||
const ModalLogin = ({ onClose, ...props }) => { | ||
const formPayload = useRef({ | ||
email: "", | ||
password: "", | ||
strategy: "local", | ||
}) | ||
|
||
const { mutate, status, error, data } = useMutation({ | ||
mutationFn: (data) => { | ||
console.info("[ModalLogin] mutate", data.email) | ||
return axios | ||
.post("/api/authentication", data) | ||
.then((res) => { | ||
console.info("[ModalLogin] mutate success", res.data) | ||
formPayload.current = { | ||
email: "", | ||
password: "", | ||
strategy: "local", | ||
} | ||
return res.data | ||
}) | ||
.catch((err) => { | ||
console.error( | ||
"[ModalLogin] mutate error", | ||
err.code, | ||
err.response?.data | ||
) | ||
|
||
return err | ||
}) | ||
}, | ||
}) | ||
|
||
const onSubmitHandler = (e) => { | ||
e.preventDefault() | ||
console.info("[ModalLogin] onSubmitHandler", formPayload.current) | ||
mutate(formPayload.current) | ||
} | ||
// # get ac | ||
return ( | ||
<ModalView viewName={ModalLoginView} onClose={onClose} {...props}> | ||
<Modal.Header closeButton> | ||
<Modal.Title id='contained-modal-title-vcenter'> | ||
Using Grid in Modal | ||
</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<Form> | ||
<Form.Group className='mb-3' controlId='ModalLoginForm.email'> | ||
<ModalView | ||
viewName={ModalLoginView} | ||
backdrop="static" | ||
onClose={onClose} | ||
{...props} | ||
> | ||
<Form onSubmit={onSubmitHandler}> | ||
<Modal.Header closeButton> | ||
<Modal.Title id="contained-modal-title-vcenter">Login</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<Form.Group className="mb-3" controlId="ModalLoginForm.email"> | ||
<Form.Label>Email address</Form.Label> | ||
<Form.Control type='email' placeholder='[email protected]' /> | ||
<Form.Control | ||
onChange={(e) => (formPayload.current.email = e.target.value)} | ||
type="email" | ||
placeholder="[email protected]" | ||
/> | ||
</Form.Group> | ||
<Form.Group className='mb-3' controlId='ModalLoginForm.password'> | ||
<Form.Group className="mb-3" controlId="ModalLoginForm.password"> | ||
<Form.Label>Password</Form.Label> | ||
<Form.Control type='password' /> | ||
<Form.Control | ||
onChange={(e) => (formPayload.current.password = e.target.value)} | ||
type="password" | ||
/> | ||
</Form.Group> | ||
</Form> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Button variant='secondary' onClick={onClose}> | ||
Close | ||
</Button> | ||
<Button variant='primary'>Understood</Button> | ||
</Modal.Footer> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Button variant="secondary" onClick={onClose}> | ||
discard | ||
</Button> | ||
<Button type="submit" variant="primary" onClick={onSubmitHandler}> | ||
login | ||
</Button> | ||
</Modal.Footer> | ||
</Form> | ||
</ModalView> | ||
) | ||
} | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useQuery } from "@tanstack/react-query" | ||
import axios from "axios" | ||
import React from "react" | ||
import { Button } from "react-bootstrap" | ||
import { ModalLoginView, useBrowserStore } from "../store" | ||
|
||
const UserArea = () => { | ||
const setView = useBrowserStore((state) => state.setView) | ||
const { status, data, error } = useQuery({ | ||
queryKey: ["me"], | ||
queryFn: () => axios.get(`/api/me`), | ||
retry: false, | ||
refetchOnMount: false, | ||
refetchOnReconnect: false, | ||
}) | ||
|
||
console.log("[UserArea]", status, data, error) | ||
return ( | ||
<div className="UserArea"> | ||
<Button | ||
size="sm" | ||
variant="transparent" | ||
onClick={() => setView(ModalLoginView)} | ||
> | ||
Log in | ||
</Button> | ||
<Button size="sm" variant="transparent"> | ||
Sign up {process.env.GATSBY_IMPRESSO_API_URL} | ||
</Button> | ||
</div> | ||
) | ||
} | ||
|
||
export default UserArea |
Oops, something went wrong.