Skip to content

Commit

Permalink
✨ Implement custom script selection (Taegon21#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
Taegon21 authored Jul 1, 2024
1 parent fda1f61 commit 2d7e0aa
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 64 deletions.
4 changes: 2 additions & 2 deletions src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import Cookies from "js-cookie";
const apiUrl = process.env.NEXT_PUBLIC_API_URL;

const apiClient = axios.create({
// baseURL: apiUrl,
baseURL: "/api",
baseURL: apiUrl,
// baseURL: "/api",
headers: {
"Content-Type": "application/json",
},
Expand Down
2 changes: 1 addition & 1 deletion src/api/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const API_ENDPOINTS = {
},
PROFESSOR: {
CHECK: (professorId: string) => `/class/${professorId}/pod`,
CREATE: (professorId: string) => `api/class/${professorId}/create`,
CREATE: (professorId: string) => `/class/${professorId}/create`,
DELETE: (professorId: string) => `/class/${professorId}/delete`,
},
};
1 change: 1 addition & 0 deletions src/api/hooks/useProfessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const useCreateClass = () => {
},
onError: (error) => {
alert(`Error: ${error.message}`);
console.log("error", error);
},
});
};
Expand Down
22 changes: 21 additions & 1 deletion src/app/(professor)/create-container/page.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
border: 1px solid #ccc;
border-radius: 12px;
width: 100%;

}

.submitButton {
Expand Down Expand Up @@ -99,6 +98,27 @@
cursor: pointer;
}

.checkboxGroup {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 10px;
margin-top: 10px;
}
.firstLine {
display: flex;
gap: 15px;
}

.checkbox {
display: flex;
align-items: center;
}

.checkbox input {
margin-right: 5px;
}

@media (max-width: 768px) {
.leftContainer {
display: none;
Expand Down
95 changes: 84 additions & 11 deletions src/app/(professor)/create-container/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const CreateContainerPage = () => {
const [classId, setClassId] = useState<string>("");
const [studentIds, setStudentIds] = useState<string[]>([""]);
const [type, setType] = useState<string>("vscode");
const [script, setScript] = useState<string>("");
const [scripts, setScripts] = useState<string[]>([]);

const { mutate: createClass, status } = useCreateClass();

Expand All @@ -20,7 +20,7 @@ const CreateContainerPage = () => {
studentIds,
options: type === "vscode" ? { vscode: "yes" } : { ssh: "yes" },
command: [],
customScript: script,
customScript: scripts,
};

const handleStudentIdChange = (index: number, value: string) => {
Expand All @@ -39,8 +39,17 @@ const CreateContainerPage = () => {
setStudentIds(newStudentIds);
};

const handleScriptChange = (value: string) => {
if (scripts.includes(value)) {
setScripts(scripts.filter((script) => script !== value));
} else {
setScripts([...scripts, value]);
}
};

const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
console.log("data:", containerData);
createClass({ professorId: studentId, classData: containerData });
};

Expand Down Expand Up @@ -117,15 +126,79 @@ const CreateContainerPage = () => {
</div>

<div className={styles.formGroup}>
<label htmlFor="port">Custom Script</label>
<input
type="text"
id="port"
placeholder="ex) apt install -y vim \n"
value={script}
onChange={(e) => setScript(e.target.value)}
required
/>
<label>Custom Script</label>
<div className={styles.checkboxGroup}>
<div className={styles.firstLine}>
<div className={styles.checkbox}>
<input
type="checkbox"
id="python"
name="customScript"
value="python"
checked={scripts.includes("python")}
onChange={(e) => handleScriptChange(e.target.value)}
/>
<label htmlFor="python">python</label>
</div>
<div className={styles.checkbox}>
<input
type="checkbox"
id="nodejs"
name="customScript"
value="nodejs"
checked={scripts.includes("nodejs")}
onChange={(e) => handleScriptChange(e.target.value)}
/>
<label htmlFor="nodejs">nodejs</label>
</div>
<div className={styles.checkbox}>
<input
type="checkbox"
id="ruby"
name="customScript"
value="ruby"
checked={scripts.includes("ruby")}
onChange={(e) => handleScriptChange(e.target.value)}
/>
<label htmlFor="ruby">ruby</label>
</div>
</div>
<div className={styles.firstLine}>
<div className={styles.checkbox}>
<input
type="checkbox"
id="vim"
name="customScript"
value="vim"
checked={scripts.includes("vim")}
onChange={(e) => handleScriptChange(e.target.value)}
/>
<label htmlFor="vim">vim</label>
</div>
<div className={styles.checkbox}>
<input
type="checkbox"
id="nginx"
name="customScript"
value="nginx"
checked={scripts.includes("nginx")}
onChange={(e) => handleScriptChange(e.target.value)}
/>
<label htmlFor="nginx">nginx</label>
</div>
<div className={styles.checkbox}>
<input
type="checkbox"
id="golang"
name="customScript"
value="golang"
checked={scripts.includes("golang")}
onChange={(e) => handleScriptChange(e.target.value)}
/>
<label htmlFor="golang">golang</label>
</div>
</div>
</div>
</div>

<button type="submit" className={styles.submitButton}>
Expand Down
7 changes: 1 addition & 6 deletions src/app/(professor)/edit-container/page.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
justify-content: space-between;
}

.saveButton,
.deleteButton {
margin-top: 30px;
padding: 10px 15px;
Expand All @@ -86,12 +85,8 @@
flex: 1;
}

.saveButton {
background-color: var(--orange-color);
}

.deleteButton {
background-color: var(--gray-color);
background-color: var(--orange-color);
}

@media (max-width: 768px) {
Expand Down
49 changes: 8 additions & 41 deletions src/app/(professor)/edit-container/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { useState } from "react";
import styles from "./page.module.css";
import Logo2Icon from "/public/icons/Logo2.svg";
import WarningModal from "@/components/common/WarningModal";
import { useDeleteClass, useFetchCheck } from "@/api/hooks/useProfessor";
import { ContainerCheckSchema, ContainerDeleteSchema } from "@/type/schemas";
import { IDelete } from "@/type/interfaces";
Expand All @@ -28,8 +27,6 @@ const EditContainerPage = () => {
const [type, setType] = useState<string>("");
const [containerStatus, setStatus] = useState<string>("");
const [command, setCommand] = useState<string>("");
const [showSaveModal, setShowSaveModal] = useState<boolean>(false);
const [showDeleteModal, setShowDeleteModal] = useState<boolean>(false);

const { data: containerCheckData, isLoading, error } = useFetchCheck();
const { mutate: deleteClass, status } = useDeleteClass();
Expand Down Expand Up @@ -69,7 +66,6 @@ const EditContainerPage = () => {
command: type === "ssh" ? command : undefined,
};
console.log("Container Data:", containerData);
setShowSaveModal(true);
};

const handleDelete = () => {
Expand All @@ -79,7 +75,6 @@ const EditContainerPage = () => {
};
console.log("Delete Data:", deleteData);
deleteClass({ professorId: studentId, deleteData: deleteData });
setShowDeleteModal(true);
};

return (
Expand All @@ -88,8 +83,10 @@ const EditContainerPage = () => {
<div className={styles.container}>
<div className={styles.leftContainer}>
<Logo2Icon />
<div className={styles.logoText}>Edit Container</div>
<div className={styles.grayText}>Edit or delete your container</div>
<div className={styles.logoText}>Delete Container</div>
<div className={styles.grayText}>
Choose Class ID to delete your container
</div>
</div>
<div className={styles.rightContainer}>
<form className={styles.form} onSubmit={handleSave}>
Expand All @@ -111,17 +108,13 @@ const EditContainerPage = () => {
</div>
<div className={styles.formGroup}>
<label htmlFor="type">Type</label>
<select
<input
id="type"
value={type}
onChange={(e) => setType(e.target.value)}
required
disabled={!classId}
>
<option value=""></option>
<option value="vscode">VSCode</option>
<option value="ssh">SSH</option>
</select>
disabled={true}
></input>
</div>

<div className={styles.formGroup}>
Expand All @@ -132,24 +125,10 @@ const EditContainerPage = () => {
value={containerStatus}
onChange={(e) => setStatus(e.target.value)}
required
disabled={type !== "vscode"}
/>
</div>
<div className={styles.formGroup}>
<label htmlFor="command">명령어</label>
<input
type="text"
id="command"
value={command}
onChange={(e) => setCommand(e.target.value)}
required
disabled={type !== "ssh"}
disabled={true}
/>
</div>
<div className={styles.buttonGroup}>
<button type="submit" className={styles.saveButton}>
수정
</button>
<button
type="button"
className={styles.deleteButton}
Expand All @@ -161,18 +140,6 @@ const EditContainerPage = () => {
</form>
</div>
</div>
{showSaveModal && (
<WarningModal
message={`"${classId}" 컨테이너가 수정되었습니다`}
onClose={() => setShowSaveModal(false)}
/>
)}
{showDeleteModal && (
<WarningModal
message={`"${classId}" 컨테이너가 삭제되었습니다`}
onClose={() => setShowDeleteModal(false)}
/>
)}
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/app/(professor)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default function Layout({ children }: LayoutProps) {
<div
className={`${styles.menuItem} ${isActive("/edit-container")}`}
>
<div>컨테이너 수정 및 삭제</div>
<div>컨테이너 삭제</div>
</div>
</Link>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/type/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface ClassCreationSchema {
studentIds: string[];
options: { [key: string]: string };
command: string[];
customScript: string;
customScript: string[];
}

export interface ContainerCheckSchema {
Expand Down

0 comments on commit 2d7e0aa

Please sign in to comment.