add
This commit is contained in:
parent
836c116a3d
commit
1a1a866406
|
@ -5,9 +5,6 @@ import type { TabsProps } from "antd";
|
||||||
import { PlayCircleOutlined } from "@ant-design/icons";
|
import { PlayCircleOutlined } from "@ant-design/icons";
|
||||||
import { CourseDetailContext } from "../CourseDetailContext";
|
import { CourseDetailContext } from "../CourseDetailContext";
|
||||||
export function CoursePreview() {
|
export function CoursePreview() {
|
||||||
const TapOnChange = (key: string) => {
|
|
||||||
console.log(key);
|
|
||||||
};
|
|
||||||
const { course, isLoading, lecture, lectureIsLoading, selectedLectureId } =
|
const { course, isLoading, lecture, lectureIsLoading, selectedLectureId } =
|
||||||
useContext(CourseDetailContext);
|
useContext(CourseDetailContext);
|
||||||
return (
|
return (
|
||||||
|
@ -37,7 +34,7 @@ export function CoursePreview() {
|
||||||
{course.subTitle}
|
{course.subTitle}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-lg font-light my-3 text-gray-500 text-clip">
|
<span className="text-lg font-light my-3 text-gray-500 text-clip">
|
||||||
{course.Description}
|
{course.content}
|
||||||
</span>
|
</span>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
@ -48,14 +45,6 @@ export function CoursePreview() {
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="overflow-auto w-11/12 mx-auto my-8">
|
|
||||||
<Tabs
|
|
||||||
defaultActiveKey="1"
|
|
||||||
tabBarGutter={100}
|
|
||||||
items={items}
|
|
||||||
onChange={TapOnChange}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@ import { createContext, useContext, ReactNode, useEffect } from "react";
|
||||||
import { Form, FormInstance, message } from "antd";
|
import { Form, FormInstance, message } from "antd";
|
||||||
import {
|
import {
|
||||||
CourseDto,
|
CourseDto,
|
||||||
|
CourseMeta,
|
||||||
CourseStatus,
|
CourseStatus,
|
||||||
ObjectType,
|
ObjectType,
|
||||||
PostType,
|
PostType,
|
||||||
|
@ -10,6 +11,7 @@ import {
|
||||||
import { api, usePost } from "@nice/client";
|
import { api, usePost } from "@nice/client";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
import { useAuth } from "@web/src/providers/auth-provider";
|
||||||
|
|
||||||
export type CourseFormData = {
|
export type CourseFormData = {
|
||||||
title: string;
|
title: string;
|
||||||
|
@ -42,6 +44,7 @@ export function CourseFormProvider({
|
||||||
}: CourseFormProviderProps) {
|
}: CourseFormProviderProps) {
|
||||||
const [form] = Form.useForm<CourseFormData>();
|
const [form] = Form.useForm<CourseFormData>();
|
||||||
const { create, update, createCourse } = usePost();
|
const { create, update, createCourse } = usePost();
|
||||||
|
const { user } = useAuth();
|
||||||
const { data: course }: { data: CourseDto } = api.post.findFirst.useQuery(
|
const { data: course }: { data: CourseDto } = api.post.findFirst.useQuery(
|
||||||
{
|
{
|
||||||
where: { id: editId },
|
where: { id: editId },
|
||||||
|
@ -77,7 +80,7 @@ export function CourseFormProvider({
|
||||||
}
|
}
|
||||||
}, [course, form]);
|
}, [course, form]);
|
||||||
|
|
||||||
const onSubmit = async (values: CourseFormData) => {
|
const onSubmit = async (values: any) => {
|
||||||
console.log(values);
|
console.log(values);
|
||||||
const sections = values?.sections || [];
|
const sections = values?.sections || [];
|
||||||
const termIds = taxonomies
|
const termIds = taxonomies
|
||||||
|
@ -87,7 +90,7 @@ export function CourseFormProvider({
|
||||||
const formattedValues = {
|
const formattedValues = {
|
||||||
...values,
|
...values,
|
||||||
meta: {
|
meta: {
|
||||||
thumbnail: values.thumbnail,
|
thumbnail: values?.meta?.thumbnail,
|
||||||
},
|
},
|
||||||
terms: {
|
terms: {
|
||||||
connect: termIds.map((id) => ({ id })), // 转换成 connect 格式
|
connect: termIds.map((id) => ({ id })), // 转换成 connect 格式
|
||||||
|
@ -98,6 +101,12 @@ export function CourseFormProvider({
|
||||||
delete formattedValues[tax.id];
|
delete formattedValues[tax.id];
|
||||||
});
|
});
|
||||||
delete formattedValues.sections;
|
delete formattedValues.sections;
|
||||||
|
if (course) {
|
||||||
|
formattedValues.meta = {
|
||||||
|
...(course?.meta as CourseMeta),
|
||||||
|
thumbnail: values?.meta?.thumbnail,
|
||||||
|
};
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if (editId) {
|
if (editId) {
|
||||||
await update.mutateAsync({
|
await update.mutateAsync({
|
||||||
|
@ -110,6 +119,7 @@ export function CourseFormProvider({
|
||||||
courseDetail: {
|
courseDetail: {
|
||||||
data: {
|
data: {
|
||||||
title: formattedValues.title || "12345",
|
title: formattedValues.title || "12345",
|
||||||
|
|
||||||
// state: CourseStatus.DRAFT,
|
// state: CourseStatus.DRAFT,
|
||||||
type: PostType.COURSE,
|
type: PostType.COURSE,
|
||||||
...formattedValues,
|
...formattedValues,
|
||||||
|
|
Loading…
Reference in New Issue