mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
fix some issues
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import { useNavigate, useParams, useLocation } from "react-router-dom";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
@@ -35,10 +35,13 @@ function FieldError({ message }) {
|
||||
|
||||
export default function AddUnit() {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const { courseId } = useParams();
|
||||
const { createUnit, fetchCourse, course, loading, syncUnitRequirements } = useCourses();
|
||||
const { user } = useAuth();
|
||||
|
||||
const backTarget = location.state?.returnTo ?? `/admin/courses/${courseId}/units`;
|
||||
|
||||
const [step, setStep] = useState(0);
|
||||
const [requirements, setRequirements] = useState([]);
|
||||
|
||||
@@ -72,7 +75,7 @@ export default function AddUnit() {
|
||||
}
|
||||
|
||||
bypassOnce();
|
||||
navigate(`/admin/courses/${courseId}/units`);
|
||||
navigate(backTarget);
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -86,13 +89,15 @@ export default function AddUnit() {
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => (step === 0 ? navigate(`/admin/courses/${courseId}/units`) : setStep(0))}
|
||||
onClick={() => (step === 0 ? navigate(backTarget) : setStep(0))}
|
||||
>
|
||||
<ChevronLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
<div>
|
||||
<h1 className="text-xl font-semibold">Create Unit</h1>
|
||||
<p className="text-sm text-muted-foreground">Add a new unit to this course.</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Creates a new unit in the shared Units Library and attaches it to this course.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -169,7 +174,7 @@ export default function AddUnit() {
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => (step === 0 ? navigate(`/admin/courses/${courseId}/units`) : setStep(0))}
|
||||
onClick={() => (step === 0 ? navigate(backTarget) : setStep(0))}
|
||||
disabled={loading}
|
||||
>
|
||||
<ChevronLeft className="h-4 w-4 mr-1" />
|
||||
|
||||
Reference in New Issue
Block a user