Skip to content

Commit

Permalink
Submit the form data to the create school endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
tuzz committed Feb 6, 2024
1 parent 7714c9f commit 48e8179
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/components/EducationIndex/EducationIndex.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { useState, useEffect } from "react";
import { useTranslation } from "react-i18next";
import * as i18nCountries from "i18n-iso-countries";
import { useDispatch, useSelector } from "react-redux";
import { syncEducation } from "../../redux/EditorSlice";

const EducationIndex = () => {
const dispatch = useDispatch();
const user = useSelector((s) => s.auth.user);
const { i18n } = useTranslation();
const [countries, setCountries] = useState([]);
const [formData, setFormData] = useState({});
Expand All @@ -27,7 +31,13 @@ const EducationIndex = () => {

const handleFormSubmit = (event) => {
event.preventDefault();
console.log(formData);

dispatch(
syncEducation("createSchool")({
requestParams: formData,
accessToken: user.access_token,
}),
);
};

return (
Expand Down
23 changes: 23 additions & 0 deletions src/redux/EditorSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
createRemix,
deleteProject,
readProjectList,
createSchool,
} from "../utils/apiCallHandler";

export const syncProject = (actionName) =>
Expand Down Expand Up @@ -76,6 +77,25 @@ export const loadProjectList = createAsyncThunk(
},
);

export const syncEducation = (actionName) =>
createAsyncThunk(
`editor/education/${actionName}`,
async ({ requestParams, accessToken }, { rejectWithValue }) => {
let response;
switch (actionName) {
case "createSchool":
response = await createSchool(requestParams, accessToken);
break;
default:
rejectWithValue({ error: "no such sync action" });
}
return { data: response.data };
},
{
condition: (_, { getState }) => {},
},
);

export const EditorSlice = createSlice({
name: "editor",
initialState: {
Expand Down Expand Up @@ -430,6 +450,9 @@ export const EditorSlice = createSlice({
builder.addCase("editor/loadProjectList/rejected", (state) => {
state.projectListLoaded = "failed";
});
builder.addCase("editor/education/createSchool", (state) => {
// TODO
});
},
});

Expand Down
4 changes: 4 additions & 0 deletions src/utils/apiCallHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,7 @@ export const createError = async (
user_id: userId,
});
};

export const createSchool = async (params, accessToken) => {
return await post(`${host}/api/schools`, params, { ...headers(accessToken) });
};

0 comments on commit 48e8179

Please sign in to comment.