move move frontend to progress-test
This commit is contained in:
75
app/javascript/services/api.ts
Normal file
75
app/javascript/services/api.ts
Normal 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;
|
||||
},
|
||||
};
|
||||
11
app/javascript/services/store/index.ts
Normal file
11
app/javascript/services/store/index.ts
Normal 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);
|
||||
1
app/javascript/services/store/unsavedChanges/index.ts
Normal file
1
app/javascript/services/store/unsavedChanges/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./reducer";
|
||||
20
app/javascript/services/store/unsavedChanges/reducer.ts
Normal file
20
app/javascript/services/store/unsavedChanges/reducer.ts
Normal 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;
|
||||
Reference in New Issue
Block a user