[M] - mandatory; [D:] - default value,
/api/auth
POST
request body
{
"email": "[M]",
"first_name": "[M]",
"password": "[M]",
"state": "[M]",
"city": "[M]",
"username": ""
}
response:
201
{}
409
{
"error": "The user with email {email} already exists"
}
{
"error": "The user with username {username} already exists'"
}
POST
request body
{
"login": "[M - username or email]",
"password": "[M]"
}
response:
200
{}
401
{
"error": "The user with email {login} does not exist"
}
{
"error": "The user with username {login} does not exist"
}
{
"error": "Wrong password"
}
POST
response:
200
{}
POST
cookies:
session
response:
200
{
"msg": "A confirmation email has been sent"
}
404
{}
406
{ "error": "Sorry, you can resend confirmation email in { ... } minutes" }
POST
request body
{
"email": ""
}
200
{
"msg": "A reset password email has been sent"
}
401
{
"error": "The user with email {email} does not exist"
}
GET
response:
200
{
"msg": "Email confirmed"
}
404
{}
POST
request body
{
"token": "",
"password": ""
}
200
{
"msg": "A new password has been saved"
}
404
{
"error": "Can not find the user"
}
406
{
"error": "The token is not valid or expired"
}
/api/account
POST
cookies:
session
request body
{
"password": "[M]"
}
response:
200
{}
404
{}
401
{
"msg": "Token has expired"
}
PATCH
cookies:
session
request body
{
"password": "[M]"
}
response:
200
{
"msg": "Password updated"
}
404
{}
401
{
"msg": "Token has expired"
}
{
"msg": "Fresh token required"
}
PATCH
cookies:
session
request body
Any of these fields:
{
"first_name": "",
"last_name": "",
"image_url": ""
}
response:
200
{
"msg": "Profile updated"
}
404
{}
401
{
"msg": "Token has expired"
}
PATCH
cookies:
session
request body
{
"username": "[M]"
}
response:
200
{
"msg": "Username updated"
}
404
json {}
401
{
"msg": "Token has expired"
}
{
"msg": "Fresh token required"
}
409
{
"msg": "The user with username {username} already exists"
}
POST
cookies:
session
request body
{
"new_email": "[M]"
}
response:
200
{
"msg": "A confirmation e-mail was sent to your {new_email} address. Please follow the instructions in the e-mail to confirm your new email"
}
**404**
json {}
**401**
```json
{
"msg": "Token has expired"
}
{
"msg": "Fresh token required"
}
409
{
"msg": "The user with email {new_email} already exists"
}
GET
response:
200
{
"msg": "Email confirmed"
}
404
json {}
/api/users
/api/chat
POST
cookies:
session
response:
200
{
"chats" :[
{
"chat_id": "",
"created_at": "",
"recipient_id"
},
]
}
POST
cookies:
session
request body:
{
"recipient_id": "[M]",
"body": "[M]"
}
response:
200
{
"chat_id": ""
}
POST
cookies:
session
request body:
{
"chat_id": "[M]"
}
response:
200
{
"chats": [
{
"created_at": "",
"sender_id": "",
"body": ""
}
]
}
/api/products
POST
cookies:
session
const {
isLoading,
data,
error,
errorNum,
sendRequest,
uploadStatus,
} = useRequest();
isLoading - [bool] is true while waiting for a response from server
data - [object] - response from a server if request is successful
error - [string] - error message
errorNum - [int] - error status number
sendRequest - [func] - function to send request
uploadStatus - [int] - shows how much data is uploaded
sendRequest(url, method, body);
url - [string]
method - [string]
body - [object]
upload - [bool] (optional) - If true
sets timeout of the request to null and allows wait until file is uploaded
const {
isLoading,
data,
error,
errorNum,
sendRequest,
uploadStatus,
} = useRequest();
const onSubmit = (formData) => {
sendRequest("/api/auth/login", "post", formData);
};
useEffect(() => {
if (data) {
history.push("/profile");
}
}, [data]);
const {modal, showModal, closeModal, isOpen} = useModal({
withBackdrop
useTimer,
inPlace,
timeOut,
disableClose
});
withBackdrop - [bool]
useTimer - [bool]
inPlace - [bool] - show modal inside the element
timeOut - [int] (default: 5000 ms) if useTimer is true
- how long the modal is shown on the screen
disableClose - [bool] (default: false
) - if true
, modal can be closed only by clicking on 'x' button
modal - created react element
showModal - [func] function to show the modal
closeModal - [func] function to close the modal
isOpen - [bool] state of the modal, true
if modal is open
showModal(children, classes);
children - element to add to modal
type - [string]: "error" - red background color, "ok" - green background color
const { modal, showModal, closeModal, isOpen } = useModal({
withBackdrop: false,
useTimer: true,
timeOut: 10000,
inPlace: false,
disableClose: true,
});
useEffect(() => {
if (error) {
showModal(error, "error");
} else if (data && data.msg) {
showModal(data.msg, "ok");
}
}, [error, errorNum, data]);
return { modal };
const {
setFormData,
handleSubmit,
handleInputChange,
formData,
formErrors,
} = useForm(inputFormData, onSubmit, formValidation);
inputFormData - initial form fields
onSubmit - function to execute after validation
formValidation - function to validate form fields
setFormData - [func] function to update form fields state
handleSubmit - [func] starts validation and if validation passed, sends request
handleInputChange - [func] updates form fields state
formData - [object] form fields state
formErrors - [object] if validation didn't pass, contains errors
Creates drag and drop container for images
const [uploadImagesContainer, filesToSend] = useUploadImages({
multipleImages,
});
multipleImages - [bool] (optional) - default false
- Allows to drop and load more then one image, max 4 images
uploadImagesContainer = [JSX element] - Drag and drop container
filesToSend = [array] - List of File
objects
Checks current width of the screen and returns isDesktop true if width is greater then breakpoint, returns screen width and height
const { isDesktop, screenWidth, screenHeight } = useScreen(breakpoint);
breakpoint - [int] (optional) - default is 600 px
isDesktop = [bool] - true
if width of the screen greater then breakpoint
screenWidth [int] - current inner width of the screen
screenHeight [int] - current inner height of the screen
Keeps track of the next and previous items inside of the ref element
const {
hasItemsOnLeft,
hasItemsOnRight,
scrollLeft,
scrollRight,
} = useElementPosition(ref);
ref - reference to the JSX element
hasItemsOnLeft - [bool] - true
if there is an element to the left of the referenced element
hasItemsOnRight - [bool] - true
if there is an element to the right of the referenced element
scrollLeft - [fn] - scrolls to the position of the element positioned to the left of the referenced element
scrollRight - scrolls to the position of the element positioned to the right of the referenced element