🪻 distributed transcription service thistle.dunkirk.sh

bug: fix the add classes button

dunkirk.sh ec636045 e55cc2b8

verified
Changed files
+31 -12
src
components
+31 -12
src/components/admin-classes.ts
···
@state() isLoading = true;
@state() error = "";
@state() searchTerm = "";
-
@state() showCreateModal = false;
+
@state() activeTab: "classes" | "waitlist" = "classes";
@state() approvingEntry: WaitlistEntry | null = null;
+
@state() showModal = false;
@state() meetingTimes: MeetingTime[] = [];
@state() editingClass = {
courseCode: "",
···
}
private handleCreateClass() {
-
this.showCreateModal = true;
+
// Set empty form for creating new class
+
this.approvingEntry = null;
+
this.editingClass = {
+
courseCode: "",
+
courseName: "",
+
professor: "",
+
semester: "",
+
year: new Date().getFullYear(),
+
};
+
this.meetingTimes = [];
+
this.showModal = true;
}
private getFilteredClasses() {
···
: this.renderWaitlist()
}
-
${this.approvingEntry ? this.renderApprovalModal() : ""}
+
${this.showModal ? this.renderApprovalModal() : ""}
`;
}
···
} else {
this.meetingTimes = [];
}
+
this.showModal = true;
}
private handleMeetingTimesChange(e: CustomEvent) {
···
}
private cancelApproval() {
+
this.showModal = false;
this.approvingEntry = null;
this.meetingTimes = [];
this.editingClass = {
···
}
private async submitApproval() {
-
if (!this.approvingEntry) return;
-
if (this.meetingTimes.length === 0) {
this.error = "Please add at least one meeting time";
return;
···
throw new Error(data.error || "Failed to create class");
}
-
await fetch(`/api/admin/waitlist/${this.approvingEntry.id}`, {
-
method: "DELETE",
-
});
+
// If approving from waitlist, delete the waitlist entry
+
if (this.approvingEntry) {
+
await fetch(`/api/admin/waitlist/${this.approvingEntry.id}`, {
+
method: "DELETE",
+
});
+
}
await this.loadData();
this.activeTab = "classes";
+
this.showModal = false;
this.approvingEntry = null;
this.meetingTimes = [];
this.editingClass = {
···
this.error =
error instanceof Error
? error.message
-
: "Failed to approve waitlist entry. Please try again.";
+
: "Failed to create class. Please try again.";
}
}
private renderApprovalModal() {
-
if (!this.approvingEntry) return "";
+
const isApproving = !!this.approvingEntry;
+
const title = isApproving ? "Review & Create Class" : "Create New Class";
+
const description = isApproving
+
? "Review the class details and make any edits before creating"
+
: "Enter the class details below";
return html`
<div class="modal-overlay" @click=${this.cancelApproval}>
<div class="modal" @click=${(e: Event) => e.stopPropagation()}>
-
<h2 class="modal-title">Review & Create Class</h2>
+
<h2 class="modal-title">${title}</h2>
<p style="margin-bottom: 1.5rem; color: var(--paynes-gray);">
-
Review the class details and make any edits before creating
+
${description}
</p>
${this.error ? html`<div class="error-message">${this.error}</div>` : ""}