-
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.
feat(course): implement course editing page #wip
- Loading branch information
Showing
7 changed files
with
155 additions
and
7 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
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,64 @@ | ||
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit' | ||
import instance from '~/axios' | ||
|
||
export const createCourse = createAsyncThunk( | ||
'course/createCourse', | ||
async (params: any) => { | ||
const { data } = await instance.post('/Course/Apply', params) | ||
|
||
return data | ||
} | ||
) | ||
|
||
export const fetchCourse = createAsyncThunk( | ||
'course/fetchCourse', | ||
async (params: any) => { | ||
const { data } = await instance.post('/Course/ViewCourse', params) | ||
|
||
return data | ||
} | ||
) | ||
|
||
export const updateBlock = createAsyncThunk( | ||
'course/updateBlock', | ||
async (params: any) => { | ||
const { data } = await instance.post('/CourseBlock/Edit', params) | ||
|
||
return data | ||
} | ||
) | ||
|
||
const initialState = { | ||
course: { | ||
data: null, | ||
isError: false, | ||
status: 'loading', | ||
}, | ||
} | ||
|
||
const courseSlice = createSlice({ | ||
name: 'course', | ||
initialState, | ||
reducers: {}, | ||
extraReducers: builder => { | ||
builder.addCase(fetchCourse.pending, (state, action) => { | ||
state.course.status = 'loading' | ||
|
||
// @ts-ignore | ||
state.course.data = null | ||
}) | ||
builder.addCase(fetchCourse.fulfilled, (state, action) => { | ||
state.course.status = 'loaded' | ||
state.course.data = action.payload.data | ||
state.course.isError = action.payload.isError | ||
}) | ||
builder.addCase(fetchCourse.rejected, (state, action) => { | ||
state.course.status = 'error' | ||
|
||
// @ts-ignore | ||
state.course.data = null | ||
}) | ||
}, | ||
}) | ||
|
||
export const courseItemReducer = courseSlice.reducer |
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,82 @@ | ||
import type { ThunkDispatch } from '@reduxjs/toolkit' | ||
import { useParams } from '@remix-run/react' | ||
import { Spinner } from 'flowbite-react' | ||
import { useEffect, useState } from 'react' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
import { fetchCourse } from '~/redux/slices/course' | ||
import { | ||
Header2, | ||
Check failure on line 8 in app/routes/edit-course.$course.tsx GitHub Actions / pipeline (21.x)
|
||
Header3, | ||
Header4, | ||
RoundedInput, | ||
TransparentButton, | ||
} from '~/shared' | ||
|
||
export default function Course() { | ||
const params = useParams() | ||
|
||
const dispatch = useDispatch<ThunkDispatch<any, any, any>>() | ||
|
||
// @ts-ignore | ||
const { course } = useSelector(state => state.course) | ||
|
||
const [isPostsLoading, setIsPostLoading] = useState(true) | ||
|
||
useEffect(() => { | ||
let formData = new FormData() | ||
formData.append('CourseID', params.course as string) | ||
console.log(params.course) | ||
// formData.append('UserID', window.localStorage.getItem("userId") as string) | ||
|
||
dispatch(fetchCourse(formData)) | ||
}, []) | ||
|
||
useEffect(() => { | ||
Check warning on line 34 in app/routes/edit-course.$course.tsx GitHub Actions / pipeline (21.x)
|
||
if (course.status === 'loaded') setIsPostLoading(false) | ||
|
||
if (course.status === 'loading') setIsPostLoading(true) | ||
}) | ||
|
||
return ( | ||
<div className="w-[1500px] min-h-screen py-12 my-[56px] mx-auto"> | ||
{isPostsLoading ? ( | ||
<div className="w-full h-screen"> | ||
<Spinner | ||
className="absolute top-1/2 left-1/2 mt-[-50px] ml-[-50px]" | ||
aria-label="Extra large spinner example" | ||
size="xl" | ||
/> | ||
</div> | ||
) : ( | ||
<div> | ||
<Header3>{course.data.name}</Header3> | ||
|
||
<img | ||
className="w-full rounded-[25px] border-2 border-[#454be9] mt-9 h-[534px]" | ||
src={ | ||
'https://mystudystorage.blob.core.windows.net/test/' + | ||
course.data.picturePath | ||
} | ||
alt="" | ||
/> | ||
|
||
<Header3 className="mt-6">Розділи курсу</Header3> | ||
|
||
<div> | ||
<Header4 className="ml-4">Додайти інформаційний блок</Header4> | ||
|
||
<div className="mt-2 flex flex-row gap-[26px]"> | ||
<RoundedInput placeholder="Назва розділу" className="w-[656px]" /> | ||
|
||
<div className=" w-[310px]"> | ||
<TransparentButton className="text-[#454BE9]"> | ||
Додати | ||
</TransparentButton> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} |
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