move move frontend to progress-test

This commit is contained in:
João Geonizeli
2022-07-21 21:16:59 -03:00
parent f8d5d08447
commit 386050d4ad
129 changed files with 159374 additions and 39 deletions

View File

@@ -0,0 +1,75 @@
const host = process.env.REACT_APP_BACKEND_URL || "http://localhost:3000";
export type LoginCredentails = {
email: string;
password: string;
};
export const authentication = {
login: async (credentails: LoginCredentails) => {
const payload = {
user: credentails,
};
const response = await fetch(`${host}/login`, {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
});
return {
token: response.headers.get("Authorization")?.replace("Bearer ", ""),
error:
response.status === 200 ? undefined : (await response.json()).error,
};
},
resetPasswordEmail: async (email: string) => {
const payload = { user: { email } };
const response = await fetch(`${host}/password`, {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
});
if (response.status === 200) return true;
return false;
},
resetPasswordByToken: async ({
reset_password_token,
password,
password_confirmation,
}: {
reset_password_token: string;
password: string;
password_confirmation: string;
}) => {
const payload = {
user: {
reset_password_token,
password,
password_confirmation,
},
};
const response = await fetch(`${host}/password`, {
method: "PUT",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
});
if (response.status === 204) return true;
return false;
},
};

View File

@@ -0,0 +1,11 @@
import { combineReducers, createStore } from "redux";
import { reducer as unsavedChanges } from "./unsavedChanges/reducer";
const rootReducer = combineReducers({
unsavedChanges,
});
export type RootState = ReturnType<typeof store.getState>;
export const store = createStore(rootReducer);

View File

@@ -0,0 +1 @@
export * from "./reducer";

View File

@@ -0,0 +1,20 @@
import { createSlice } from "@reduxjs/toolkit";
const slice = createSlice({
name: "unsavedChanges",
initialState: false,
reducers: {
turnOn: (state) => {
state = true;
return state;
},
turnOff: (state) => {
state = false;
return state;
},
},
});
export const { turnOff, turnOn } = slice.actions;
export const reducer = slice.reducer;