coursekit-lms 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/README.md +127 -26
  3. package/dist/cli/index.js +7139 -1633
  4. package/dist/cli/index.js.map +1 -1
  5. package/dist/server/index.js +7128 -1655
  6. package/dist/server/index.js.map +1 -1
  7. package/dist/types/server/config.d.ts +4 -0
  8. package/dist/types/server/db/migrations/002_email.d.ts +8 -0
  9. package/dist/types/server/db/migrations/003_groups_cohorts.d.ts +7 -0
  10. package/dist/types/server/db/migrations/004_completion_badges.d.ts +8 -0
  11. package/dist/types/server/db/migrations/005_question_bank.d.ts +11 -0
  12. package/dist/types/server/db/migrations/006_grade_categories.d.ts +11 -0
  13. package/dist/types/server/db/schema-completion.d.ts +79 -0
  14. package/dist/types/server/db/schema.d.ts +165 -5
  15. package/dist/types/server/index.d.ts +7 -0
  16. package/dist/types/server/lib/events.d.ts +105 -0
  17. package/dist/types/server/routes/badges.d.ts +4 -0
  18. package/dist/types/server/routes/certificates.d.ts +3 -0
  19. package/dist/types/server/routes/cohorts.d.ts +6 -0
  20. package/dist/types/server/routes/completion.d.ts +4 -0
  21. package/dist/types/server/routes/email.d.ts +13 -0
  22. package/dist/types/server/routes/grade-categories.d.ts +4 -0
  23. package/dist/types/server/routes/groups.d.ts +4 -0
  24. package/dist/types/server/routes/question-bank.d.ts +4 -0
  25. package/dist/types/server/seed/demo-completion.d.ts +2 -0
  26. package/dist/types/server/seed/demo-email.d.ts +2 -0
  27. package/dist/types/server/seed/demo-grade-categories.d.ts +6 -0
  28. package/dist/types/server/seed/demo-groups.d.ts +6 -0
  29. package/dist/types/server/seed/demo-question-bank.d.ts +20 -0
  30. package/dist/types/server/services/badges.d.ts +39 -0
  31. package/dist/types/server/services/certificates.d.ts +42 -0
  32. package/dist/types/server/services/cohorts.d.ts +64 -0
  33. package/dist/types/server/services/completion.d.ts +63 -0
  34. package/dist/types/server/services/course-total.d.ts +107 -0
  35. package/dist/types/server/services/email/config.d.ts +55 -0
  36. package/dist/types/server/services/email/digests.d.ts +57 -0
  37. package/dist/types/server/services/email/outbox.d.ts +61 -0
  38. package/dist/types/server/services/email/preferences.d.ts +25 -0
  39. package/dist/types/server/services/email/service.d.ts +116 -0
  40. package/dist/types/server/services/email/templates.d.ts +74 -0
  41. package/dist/types/server/services/email/tokens.d.ts +11 -0
  42. package/dist/types/server/services/email/transport.d.ts +29 -0
  43. package/dist/types/server/services/enrolments.d.ts +32 -0
  44. package/dist/types/server/services/grade-categories.d.ts +31 -0
  45. package/dist/types/server/services/gradebook.d.ts +18 -0
  46. package/dist/types/server/services/groups.d.ts +90 -0
  47. package/dist/types/server/services/notify.d.ts +4 -1
  48. package/dist/types/server/services/question-bank.d.ts +53 -0
  49. package/dist/types/server/services/question-types.d.ts +146 -0
  50. package/dist/types/server/services/quiz-slots.d.ts +33 -0
  51. package/dist/types/server/services/quiz.d.ts +45 -14
  52. package/dist/types/shared/completion.d.ts +214 -0
  53. package/dist/types/shared/email.d.ts +117 -0
  54. package/dist/types/shared/grades.d.ts +18 -0
  55. package/dist/types/shared/groups.d.ts +17 -0
  56. package/dist/types/shared/permissions.d.ts +1 -1
  57. package/dist/types/shared/types.d.ts +268 -2
  58. package/dist/web/assets/{ActivityEditor-BVSZUV8l.js → ActivityEditor-BNG3aTQa.js} +2 -2
  59. package/dist/web/assets/ActivityPage-i0XHYD2Q.js +1 -0
  60. package/dist/web/assets/AdminBadgesPage-DvpxIg1P.js +1 -0
  61. package/dist/web/assets/AdminCohortsPage-B5PWBkjp.js +3 -0
  62. package/dist/web/assets/AdminCoursesPage-Dm1ECbS-.js +1 -0
  63. package/dist/web/assets/AdminEmailPage-D3E_Db1_.js +1 -0
  64. package/dist/web/assets/AdminLayout-BVeduyCQ.js +1 -0
  65. package/dist/web/assets/{AdminOverviewPage-DnTrdGbr.js → AdminOverviewPage-BaCKvhgr.js} +1 -1
  66. package/dist/web/assets/{AdminSettingsPage-B82cX8xU.js → AdminSettingsPage-B5Ag5K15.js} +1 -1
  67. package/dist/web/assets/AdminUsersPage-BVCG65EK.js +1 -0
  68. package/dist/web/assets/{AnnouncementsPage-BKW30k0Z.js → AnnouncementsPage-C0OAzyvW.js} +1 -1
  69. package/dist/web/assets/BadgePage-B3Ecudas.js +1 -0
  70. package/dist/web/assets/CalendarPage-CEks5F4m.js +1 -0
  71. package/dist/web/assets/{CatalogPage-BiMgSSBR.js → CatalogPage-e7lVtwUN.js} +1 -1
  72. package/dist/web/assets/CertificatePage-_eSGt8R-.js +9 -0
  73. package/dist/web/assets/CompletionPage-Dxp-ulA_.js +1 -0
  74. package/dist/web/assets/CourseBadgesPage-Vi3P1Lnc.js +1 -0
  75. package/dist/web/assets/CourseContentPage-IFlhVsO5.js +1 -0
  76. package/dist/web/assets/CourseLayout-BqwXol8L.js +1 -0
  77. package/dist/web/assets/CourseSettingsPage-BIagLirb.js +1 -0
  78. package/dist/web/assets/CreateCoursePage-BBcdiTtz.js +1 -0
  79. package/dist/web/assets/{DiscussionPage-CWwVpFQV.js → DiscussionPage-C23QoCSw.js} +1 -1
  80. package/dist/web/assets/GradebookSetupPage-a5GH4xIk.js +1 -0
  81. package/dist/web/assets/GradesPage-CY6MtJxs.js +1 -0
  82. package/dist/web/assets/GroupsPage-DS3HFeC4.js +1 -0
  83. package/dist/web/assets/{MyCoursesPage-Dd-Oaygv.js → MyCoursesPage-Ckj-1SCA.js} +1 -1
  84. package/dist/web/assets/{NotFoundPage-BRquC7-l.js → NotFoundPage-BmwVsGAy.js} +1 -1
  85. package/dist/web/assets/NotificationsPage-DBRM37F1.js +1 -0
  86. package/dist/web/assets/ParticipantsPage-DV4Mjfxo.js +1 -0
  87. package/dist/web/assets/ProfilePage-BqG55_02.js +1 -0
  88. package/dist/web/assets/QuestionAnswer-CJIoWSz2.js +1 -0
  89. package/dist/web/assets/QuestionBankPage-BkI44c4K.js +1 -0
  90. package/dist/web/assets/QuizAttemptPage-DQVfbLKI.js +1 -0
  91. package/dist/web/assets/QuizEditorPage-muk-KVG1.js +1 -0
  92. package/dist/web/assets/SubmissionsPage-Dx97JOzE.js +1 -0
  93. package/dist/web/assets/UnsubscribePage-BPLiTiaG.js +1 -0
  94. package/dist/web/assets/VerifyCertificatePage-Cw9iXN3C.js +1 -0
  95. package/dist/web/assets/achievements-DaIfUTKU.js +1 -0
  96. package/dist/web/assets/{arrow-up-LHDup5m4.js → arrow-up-lI30bvj5.js} +1 -1
  97. package/dist/web/assets/badge-art-QPo-pYql.js +1 -0
  98. package/dist/web/assets/badge-card-ByT0wR6q.js +1 -0
  99. package/dist/web/assets/badge-dialog-p2zTk4h0.js +1 -0
  100. package/dist/web/assets/{ban-D3Vsxg_g.js → ban-DEiI8npI.js} +1 -1
  101. package/dist/web/assets/bank-S3XEFPfe.js +3 -0
  102. package/dist/web/assets/bell-off-Bo2RE0kn.js +1 -0
  103. package/dist/web/assets/calendar-range-Cfg-P4Md.js +1 -0
  104. package/dist/web/assets/certificate-sheet-DzW0lfzR.js +2 -0
  105. package/dist/web/assets/chevron-left-Bu6IJANV.js +1 -0
  106. package/dist/web/assets/circle-dashed-D34ZjnSx.js +1 -0
  107. package/dist/web/assets/clock-DPBmdKAi.js +1 -0
  108. package/dist/web/assets/cohorts-DL0Dsxva.js +1 -0
  109. package/dist/web/assets/completion-2z7I-ypT.js +1 -0
  110. package/dist/web/assets/contact-NCWQa7wc.js +1 -0
  111. package/dist/web/assets/{context-BLVW7NB7.js → context-D8W_QqNi.js} +1 -1
  112. package/dist/web/assets/{copy-Bxxjq6zo.js → copy-B5IKRMFo.js} +1 -1
  113. package/dist/web/assets/download-BrtK5sVk.js +1 -0
  114. package/dist/web/assets/{ellipsis-c2POIN-Y.js → ellipsis-BDmYLoyn.js} +1 -1
  115. package/dist/web/assets/email-BZ3kGs-R.js +1 -0
  116. package/dist/web/assets/flag-DOzXVys0.js +1 -0
  117. package/dist/web/assets/folder-input-M2p_UJZX.js +1 -0
  118. package/dist/web/assets/{library-3WG9oLCb.js → folder-tree-B-DoLXMB.js} +1 -1
  119. package/dist/web/assets/frame-DZh5g5b3.js +1 -0
  120. package/dist/web/assets/globe-DDTr53UY.js +1 -0
  121. package/dist/web/assets/grades-ogaD0MDO.js +1 -0
  122. package/dist/web/assets/groups-CrYV_AFp.js +1 -0
  123. package/dist/web/assets/{hooks-BBARn-DA.js → hooks-EFhyJ5yU.js} +1 -1
  124. package/dist/web/assets/hourglass-BKca6Cje.js +1 -0
  125. package/dist/web/assets/inbox-x1U4YU-c.js +1 -0
  126. package/dist/web/assets/index-BdPmMS6n.css +2 -0
  127. package/dist/web/assets/index-CEZdqKdi.js +50 -0
  128. package/dist/web/assets/{key-round-B_KI-brR.js → key-round-fzvV-etw.js} +1 -1
  129. package/dist/web/assets/library-Bcm33ouq.js +1 -0
  130. package/dist/web/assets/lightbulb-CjSpJ1_v.js +1 -0
  131. package/dist/web/assets/{lock-BjbqwA_0.js → lock-C2edVDOc.js} +1 -1
  132. package/dist/web/assets/mail-CQ9yiBph.js +1 -0
  133. package/dist/web/assets/mail-x-B6oBqlcw.js +1 -0
  134. package/dist/web/assets/{markdown-ykrkPMbn.js → markdown-HNlXovsL.js} +3 -3
  135. package/dist/web/assets/message-square-text-wvO9_guT.js +1 -0
  136. package/dist/web/assets/{misc-DvgDEI3I.js → misc-CyGhN6HT.js} +1 -1
  137. package/dist/web/assets/{pencil-p0GQmIMo.js → pencil-DFUpj3YP.js} +1 -1
  138. package/dist/web/assets/{pin-DlYC3uec.js → pin-DNUQ6-WX.js} +1 -1
  139. package/dist/web/assets/revoke-dialog-DjBKaFTV.js +1 -0
  140. package/dist/web/assets/rotate-ccw-yBj9Ri49.js +1 -0
  141. package/dist/web/assets/scroll-text-RmPlZi3F.js +1 -0
  142. package/dist/web/assets/{send-mxSHcdcD.js → send-BnVkFV8w.js} +1 -1
  143. package/dist/web/assets/{settings-DRKWzSHN.js → settings-BxdCrDf8.js} +1 -1
  144. package/dist/web/assets/shield-x-RpNHS0o8.js +1 -0
  145. package/dist/web/assets/shuffle-C1aB_4dp.js +1 -0
  146. package/dist/web/assets/target-G9Q_WQLB.js +1 -0
  147. package/dist/web/assets/trophy-BFFngFEh.js +1 -0
  148. package/dist/web/assets/user-minus-CkOPT3ak.js +1 -0
  149. package/dist/web/assets/users-round-CNhv0Whm.js +1 -0
  150. package/dist/web/index.html +4 -4
  151. package/package.json +6 -1
  152. package/dist/web/assets/ActivityPage-DPmSV_mU.js +0 -1
  153. package/dist/web/assets/AdminCoursesPage-uaSHNtzf.js +0 -1
  154. package/dist/web/assets/AdminLayout-DqoShZGn.js +0 -1
  155. package/dist/web/assets/AdminUsersPage-3d2F9AEl.js +0 -1
  156. package/dist/web/assets/CalendarPage-CLRWyTNT.js +0 -1
  157. package/dist/web/assets/CourseContentPage-BIDH0UbG.js +0 -1
  158. package/dist/web/assets/CourseLayout-ql01LEmj.js +0 -1
  159. package/dist/web/assets/CourseSettingsPage-CReoPqOa.js +0 -1
  160. package/dist/web/assets/CreateCoursePage-DFCHlq5M.js +0 -1
  161. package/dist/web/assets/GradesPage-Bu5vphcG.js +0 -1
  162. package/dist/web/assets/NotificationsPage-LJvqb6Dj.js +0 -1
  163. package/dist/web/assets/ParticipantsPage-wFxiphna.js +0 -1
  164. package/dist/web/assets/ProfilePage-CzfhacAX.js +0 -1
  165. package/dist/web/assets/QuizAttemptPage-CEAV6wAL.js +0 -1
  166. package/dist/web/assets/QuizEditorPage-DS_czQVM.js +0 -3
  167. package/dist/web/assets/SubmissionsPage-CQjcx09G.js +0 -1
  168. package/dist/web/assets/chevron-left-D6IMQD6N.js +0 -1
  169. package/dist/web/assets/frame-CGabirLa.js +0 -1
  170. package/dist/web/assets/index-B29bTBiJ.js +0 -50
  171. package/dist/web/assets/index-WxCvsbJq.css +0 -2
  172. package/dist/web/assets/message-square-text-fe24gbEU.js +0 -1
  173. package/dist/web/assets/trophy-Cch2iF1m.js +0 -1
@@ -9,7 +9,7 @@ export type CourseVisibility = 'draft' | 'published' | 'archived';
9
9
  export type EnrolmentMethod = 'open' | 'key' | 'invite';
10
10
  export type ActivityType = 'lesson' | 'resource' | 'assignment' | 'quiz' | 'forum';
11
11
  export type CompletionMode = 'none' | 'manual' | 'auto';
12
- export type QuestionType = 'single' | 'multiple' | 'truefalse' | 'short' | 'numeric';
12
+ export type QuestionType = 'single' | 'multiple' | 'truefalse' | 'short' | 'numeric' | 'essay' | 'matching' | 'ordering';
13
13
  export interface PublicUser {
14
14
  id: string;
15
15
  name: string;
@@ -78,6 +78,8 @@ export interface CourseDetail extends CourseSummary {
78
78
  canEnrol: boolean;
79
79
  /** True when the viewer can only see the outline (not enrolled). */
80
80
  outlineOnly: boolean;
81
+ /** The viewer's own groups in this course. */
82
+ myGroups?: GroupRef[];
81
83
  }
82
84
  export interface Section {
83
85
  id: string;
@@ -169,7 +171,8 @@ export interface Submission {
169
171
  export interface QuizAttemptSummary {
170
172
  id: string;
171
173
  attemptNumber: number;
172
- status: 'in_progress' | 'finished';
174
+ /** `needs_grading`: submitted, waiting for a teacher to mark essays (the score is pending). */
175
+ status: 'in_progress' | 'needs_grading' | 'finished';
173
176
  startedAt: string;
174
177
  finishedAt: string | null;
175
178
  score: number | null;
@@ -183,6 +186,8 @@ export interface QuizInfo {
183
186
  attemptsUsed: number;
184
187
  canAttempt: boolean;
185
188
  inProgressAttemptId: string | null;
189
+ /** Staff only: students' attempts waiting for essays to be marked. */
190
+ needsGrading?: number;
186
191
  }
187
192
  export interface ActivityDetail<T extends ActivityType = ActivityType> extends ActivitySummary {
188
193
  type: T;
@@ -223,22 +228,44 @@ export interface Question {
223
228
  type: QuestionType;
224
229
  prompt: string;
225
230
  points: number;
231
+ /** Choices; for ordering, the items (shown order during an attempt, right order for editors and in review). */
226
232
  options: QuestionOption[];
227
233
  /** short/numeric: accepted answers (editors and review only). */
228
234
  acceptedAnswers?: string[];
229
235
  /** numeric: allowed +/- error (editors and review only). */
230
236
  tolerance?: number | null;
231
237
  explanation?: string | null;
238
+ /** matching: the items to match; `answer` and `answerId` only for editors and in review. */
239
+ pairs?: MatchPair[];
240
+ /** matching: the answers to choose from, in display order (distractors included). */
241
+ choices?: QuestionOption[];
242
+ /** matching: extra wrong answers (editors only). */
243
+ distractors?: string[];
244
+ /** essay: suggested length. */
245
+ minWords?: number | null;
246
+ maxWords?: number | null;
247
+ /** essay: information for graders (staff only, never sent to students). */
248
+ graderNotes?: string | null;
232
249
  }
233
250
  export interface AttemptAnswer {
234
251
  optionIds?: string[];
235
252
  text?: string;
253
+ /** ordering: item ids in the student's order. */
254
+ order?: string[];
255
+ /** matching: chosen answer id for each item id. */
256
+ matches?: Record<string, string>;
236
257
  }
237
258
  export interface QuestionResult {
238
259
  correct: boolean;
239
260
  partial: boolean;
240
261
  points: number;
241
262
  maxPoints: number;
263
+ /** essay: waiting for a teacher's mark. */
264
+ pending?: boolean;
265
+ /** Manual grading: the grader's comment for the student. */
266
+ comment?: string | null;
267
+ gradedBy?: PublicUser | null;
268
+ gradedAt?: string | null;
242
269
  }
243
270
  export interface QuizAttempt extends QuizAttemptSummary {
244
271
  activityId: string;
@@ -249,8 +276,13 @@ export interface QuizAttempt extends QuizAttemptSummary {
249
276
  answers: Record<string, AttemptAnswer>;
250
277
  /** Whether correct answers are included. */
251
278
  review: boolean;
279
+ /** Per-question results; without review only manually graded (essay) results are included. */
252
280
  results: Record<string, QuestionResult> | null;
253
281
  passingPercent: number | null;
282
+ /** Essays still waiting for a mark. */
283
+ pendingCount: number;
284
+ /** The viewer may mark essays in this attempt. */
285
+ canGrade: boolean;
254
286
  }
255
287
  export interface Discussion {
256
288
  id: string;
@@ -300,6 +332,8 @@ export interface Participant {
300
332
  enrolledAt: string;
301
333
  lastAccessAt: string | null;
302
334
  progress: number | null;
335
+ /** The person's groups, limited to the groups the viewer may see (students only see their own). */
336
+ groups?: GroupRef[];
303
337
  }
304
338
  export interface GradebookItem {
305
339
  activityId: string;
@@ -307,35 +341,110 @@ export interface GradebookItem {
307
341
  type: ActivityType;
308
342
  maxGrade: number;
309
343
  dueAt: string | null;
344
+ /** The grade category the item counts in (the default category's id is the course id). */
345
+ categoryId: string;
346
+ /** Weight within its category in weighted aggregation; null means "by points" (the item's max grade). */
347
+ weight: number | null;
310
348
  }
311
349
  export interface GradebookCell {
312
350
  score: number | null;
313
351
  feedback: string | null;
352
+ /** Left out of the totals by its category's "drop the lowest" rule. */
353
+ dropped: boolean;
314
354
  }
315
355
  export interface GradebookRow {
316
356
  user: PublicUser & {
317
357
  email: string;
318
358
  };
319
359
  cells: Record<string, GradebookCell>;
360
+ /** Points earned and possible on the work that counts (after drop-lowest). The natural total is total / max. */
320
361
  total: number;
321
362
  max: number;
363
+ /** The course total, 0-100 with 2 decimals, or null when nothing is graded yet. */
322
364
  percentage: number | null;
365
+ /** Category subtotals, keyed by category id. */
366
+ categories: Record<string, GradeCategoryResult>;
323
367
  }
324
368
  export interface Gradebook {
325
369
  items: GradebookItem[];
326
370
  rows: GradebookRow[];
327
371
  averages: Record<string, number | null>;
328
372
  courseAverage: number | null;
373
+ aggregation: GradeAggregation;
374
+ /** Every category in order, including the default one (even when empty). */
375
+ categories: GradeCategory[];
376
+ /** Average category subtotal per category id. */
377
+ categoryAverages: Record<string, number | null>;
329
378
  }
330
379
  export interface MyGrades {
331
380
  items: Array<GradebookItem & {
332
381
  score: number | null;
333
382
  feedback: string | null;
334
383
  gradedAt: string | null;
384
+ dropped: boolean;
335
385
  }>;
336
386
  total: number;
337
387
  max: number;
338
388
  percentage: number | null;
389
+ aggregation: GradeAggregation;
390
+ categories: Array<GradeCategory & GradeCategoryResult>;
391
+ }
392
+ /**
393
+ * How the course total is calculated. "natural" adds up points (what 0.1.x did, and the default);
394
+ * "weighted" makes each category worth a share of the total.
395
+ */
396
+ export type GradeAggregation = 'natural' | 'weighted';
397
+ export interface GradeCategory {
398
+ id: string;
399
+ name: string;
400
+ /** Share of the course total in weighted aggregation, 0-100. Normalised over the categories that have grades. */
401
+ weight: number;
402
+ /** Leave out this many of the lowest graded items (at least one graded item always counts). */
403
+ dropLowest: number;
404
+ position: number;
405
+ /** Activities that aren't assigned to a category count here. Its id is the course id and it can't be deleted. */
406
+ isDefault: boolean;
407
+ }
408
+ export interface GradeCategoryResult {
409
+ /** Category subtotal, 0-100 with 2 decimals, or null when nothing in it counts yet. */
410
+ percentage: number | null;
411
+ /** Points earned and possible on the items that count (after drop-lowest). Weighted courses may also use item weights. */
412
+ earned: number;
413
+ possible: number;
414
+ /** Share of the course total this category carries right now (0-100), or null when it doesn't count. */
415
+ share: number | null;
416
+ }
417
+ /** A graded activity as the gradebook setup sees it. */
418
+ export interface GradeItemSetting {
419
+ activityId: string;
420
+ title: string;
421
+ type: ActivityType;
422
+ maxGrade: number;
423
+ visible: boolean;
424
+ sectionTitle: string;
425
+ categoryId: string;
426
+ weight: number | null;
427
+ }
428
+ export interface GradebookSetup {
429
+ aggregation: GradeAggregation;
430
+ categories: GradeCategory[];
431
+ /** Every graded activity (hidden ones too) in course order. */
432
+ items: GradeItemSetting[];
433
+ }
434
+ /** Body of `PUT /courses/:id/grades/setup`. Categories are listed in display order; new ones use any temporary id. */
435
+ export interface GradebookSetupInput {
436
+ aggregation: GradeAggregation;
437
+ categories: Array<{
438
+ id: string;
439
+ name: string;
440
+ weight: number;
441
+ dropLowest: number;
442
+ }>;
443
+ items?: Array<{
444
+ activityId: string;
445
+ categoryId: string;
446
+ weight: number | null;
447
+ }>;
339
448
  }
340
449
  export interface TimelineItem {
341
450
  activityId: string;
@@ -450,3 +559,160 @@ export interface ApiErrorBody {
450
559
  }>;
451
560
  };
452
561
  }
562
+ export interface GroupRef {
563
+ id: string;
564
+ name: string;
565
+ }
566
+ export interface GroupMember extends PublicUser {
567
+ role: CourseRole;
568
+ status: 'active' | 'suspended';
569
+ }
570
+ export interface CourseGroup extends GroupRef {
571
+ description: string;
572
+ /** Enrolled members. Students only see the active members of their own groups. */
573
+ members: GroupMember[];
574
+ createdAt: string;
575
+ }
576
+ export interface CourseGroups {
577
+ groups: CourseGroup[];
578
+ /** Whether the viewer can create, rename and delete groups and change who is in them. */
579
+ canManage: boolean;
580
+ /** False when the viewer only sees the groups they belong to (students). */
581
+ allGroups: boolean;
582
+ }
583
+ export interface GroupMembersAdded {
584
+ /** User ids added to the group. */
585
+ added: string[];
586
+ alreadyMembers: string[];
587
+ /** Ids of people who aren't enrolled in the course, so can't join its groups. */
588
+ notEnrolled: string[];
589
+ }
590
+ export interface CohortSummary {
591
+ id: string;
592
+ name: string;
593
+ description: string;
594
+ memberCount: number;
595
+ /** Courses the cohort is linked to. */
596
+ courseCount: number;
597
+ createdAt: string;
598
+ }
599
+ export interface CohortLink {
600
+ id: string;
601
+ cohort: {
602
+ id: string;
603
+ name: string;
604
+ memberCount: number;
605
+ };
606
+ course: CourseRef;
607
+ /** The course role linked members are enrolled with. */
608
+ role: CourseRole;
609
+ createdAt: string;
610
+ }
611
+ export interface CohortDetail extends CohortSummary {
612
+ links: CohortLink[];
613
+ }
614
+ export interface CohortMember extends PublicUser {
615
+ email: string;
616
+ status: UserStatus;
617
+ addedAt: string;
618
+ }
619
+ /** A person found when searching for people to add to a cohort. */
620
+ export interface CohortCandidate extends PublicUser {
621
+ email: string;
622
+ member: boolean;
623
+ }
624
+ export interface CohortMembersAdded {
625
+ added: number;
626
+ /** Emails (or ids) of people who were already in the cohort. */
627
+ alreadyMembers: string[];
628
+ /** Emails (or ids) with no account on the site. */
629
+ notFound: string[];
630
+ /** Entries that aren't email addresses. */
631
+ invalid: string[];
632
+ /** New course enrolments made through the cohort's linked courses. */
633
+ enrolled: number;
634
+ }
635
+ export interface CohortOption {
636
+ id: string;
637
+ name: string;
638
+ memberCount: number;
639
+ }
640
+ export interface MatchPair {
641
+ id: string;
642
+ text: string;
643
+ /** The matching answer (editors and review only). */
644
+ answer?: string;
645
+ /** Id of the right choice (review only). */
646
+ answerId?: string;
647
+ }
648
+ export interface QuestionCategory {
649
+ id: string;
650
+ courseId: string;
651
+ parentId: string | null;
652
+ name: string;
653
+ description: string;
654
+ position: number;
655
+ /** Questions directly in this category. */
656
+ questionCount: number;
657
+ createdAt: string;
658
+ }
659
+ export interface QuestionUsage {
660
+ activityId: string;
661
+ title: string;
662
+ /** `question`: added to the quiz; `random`: in the pool of one of its random slots. */
663
+ kind: 'question' | 'random';
664
+ }
665
+ /** A question bank entry with its answers (staff only). */
666
+ export interface BankQuestion extends Question {
667
+ name: string;
668
+ categoryId: string;
669
+ createdAt: string;
670
+ updatedAt: string;
671
+ usage: QuestionUsage[];
672
+ }
673
+ export interface BankQuestionSummary {
674
+ id: string;
675
+ type: QuestionType;
676
+ name: string;
677
+ /** Plain-text preview of the prompt. */
678
+ excerpt: string;
679
+ points: number;
680
+ categoryId: string;
681
+ categoryName: string;
682
+ /** Quizzes that use the question directly. */
683
+ quizCount: number;
684
+ updatedAt: string;
685
+ }
686
+ export interface QuizSlotInfo {
687
+ id: string;
688
+ kind: 'question' | 'random';
689
+ /** Mark for each question in the slot. */
690
+ points: number;
691
+ /** 1 for a question slot. */
692
+ questionCount: number;
693
+ question: BankQuestionSummary | null;
694
+ category: {
695
+ id: string;
696
+ name: string;
697
+ } | null;
698
+ includeSubcategories: boolean;
699
+ /** Random slots: questions available to pick from (not already in the quiz). */
700
+ available: number | null;
701
+ /** Random slots: questions needed from these categories by this and narrower random slots. */
702
+ needed: number | null;
703
+ }
704
+ export interface QuizSlots {
705
+ slots: QuizSlotInfo[];
706
+ questionCount: number;
707
+ totalPoints: number;
708
+ /** Reasons an attempt couldn't start, e.g. too few questions for a random slot. */
709
+ problems: string[];
710
+ }
711
+ export interface QuizGradingItem {
712
+ attemptId: string;
713
+ attemptNumber: number;
714
+ user: PublicUser;
715
+ finishedAt: string | null;
716
+ /** Essays waiting for a mark. */
717
+ pending: number;
718
+ }
@@ -1,3 +1,3 @@
1
- import{F as e,H as t,U as n,dt as r,ft as i,g as a,h as o,k as s,m as c,mt as l}from"./hooks-BBARn-DA.js";import{T as u,i as d}from"./misc-DvgDEI3I.js";import{r as f}from"./markdown-ykrkPMbn.js";import{C as p,D as m,E as h,Ft as g,O as _,Rt as v,T as y,c as b,d as x,f as S,i as C,k as w,kt as T,l as E,p as D,r as O,s as k,u as A,v as j,w as M}from"./index-B29bTBiJ.js";import{a as N}from"./context-BLVW7NB7.js";import{a as P,i as F,n as I,t as L}from"./constants-DLDWTvvN.js";var R={name:`circle`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]};R.node;var z=t(R),B=l(i(),1),V=r(),H={lesson:`When the lesson is opened`,resource:`When the resource is opened`,assignment:`When work is submitted`,quiz:`When an attempt is finished (and passed, if a pass mark is set)`,forum:`When the student posts`};function U(e){return{type:e,title:``,description:``,visible:!0,completion:F[e],dueAt:``,maxGrade:e===`assignment`?`100`:``,settings:structuredClone(P[e])}}function W({onPick:e}){return(0,V.jsx)(`div`,{className:`grid gap-2.5 sm:grid-cols-2`,children:I.map(t=>(0,V.jsxs)(`button`,{type:`button`,onClick:()=>e(t),className:`flex items-start gap-3 rounded-xl border bg-card p-4 text-left transition-all hover:-translate-y-px hover:border-primary/40 hover:shadow-md`,children:[(0,V.jsx)(j,{type:t,size:`lg`}),(0,V.jsxs)(`span`,{children:[(0,V.jsx)(`span`,{className:`block text-sm font-semibold`,children:p[t].label}),(0,V.jsx)(`span`,{className:`mt-0.5 block text-xs leading-snug text-muted-foreground`,children:L[t]})]})]},t))})}function G({form:e,setForm:t,course:n}){let r=(n,r)=>t({...e,[n]:r}),i=n=>t({...e,settings:{...e.settings,...n}}),[a,o]=(0,B.useState)(null);switch(e.type){case`lesson`:{let t=e.settings;return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(E,{label:`Lesson content`,children:e=>(0,V.jsx)(f,{id:e.id,value:t.body,onChange:e=>i({body:e}),rows:14,placeholder:`# Lesson title
1
+ import{F as e,H as t,U as n,dt as r,ft as i,g as a,h as o,k as s,m as c,mt as l}from"./hooks-EFhyJ5yU.js";import{E as u,i as d}from"./misc-CyGhN6HT.js";import{r as f}from"./markdown-HNlXovsL.js";import{A as p,D as m,E as h,Ft as g,Gt as _,Ht as v,O as y,T as b,c as x,d as S,f as C,i as w,k as T,l as E,p as D,r as O,s as k,u as A,w as j,y as M}from"./index-CEZdqKdi.js";import{a as N}from"./context-D8W_QqNi.js";import{a as P,i as F,n as I,t as L}from"./constants-DLDWTvvN.js";var R={name:`circle`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]};R.node;var z=t(R),B=l(i(),1),V=r(),H={lesson:`When the lesson is opened`,resource:`When the resource is opened`,assignment:`When work is submitted`,quiz:`When an attempt is finished (and passed, if a pass mark is set)`,forum:`When the student posts`};function U(e){return{type:e,title:``,description:``,visible:!0,completion:F[e],dueAt:``,maxGrade:e===`assignment`?`100`:``,settings:structuredClone(P[e])}}function W({onPick:e}){return(0,V.jsx)(`div`,{className:`grid gap-2.5 sm:grid-cols-2`,children:I.map(t=>(0,V.jsxs)(`button`,{type:`button`,onClick:()=>e(t),className:`flex items-start gap-3 rounded-xl border bg-card p-4 text-left transition-all hover:-translate-y-px hover:border-primary/40 hover:shadow-md`,children:[(0,V.jsx)(M,{type:t,size:`lg`}),(0,V.jsxs)(`span`,{children:[(0,V.jsx)(`span`,{className:`block text-sm font-semibold`,children:j[t].label}),(0,V.jsx)(`span`,{className:`mt-0.5 block text-xs leading-snug text-muted-foreground`,children:L[t]})]})]},t))})}function G({form:e,setForm:t,course:n}){let r=(n,r)=>t({...e,[n]:r}),i=n=>t({...e,settings:{...e.settings,...n}}),[a,o]=(0,B.useState)(null);switch(e.type){case`lesson`:{let t=e.settings;return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(E,{label:`Lesson content`,children:e=>(0,V.jsx)(f,{id:e.id,value:t.body,onChange:e=>i({body:e}),rows:14,placeholder:`# Lesson title
2
2
 
3
- Write your lesson here…`})}),(0,V.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-[1fr_180px]`,children:[(0,V.jsx)(E,{label:`Video URL`,optional:!0,hint:`YouTube, Vimeo or a direct .mp4 link.`,children:e=>(0,V.jsx)(A,{...e,value:t.videoUrl??``,onChange:e=>i({videoUrl:e.target.value||null}),placeholder:`https://www.youtube.com/watch?v=…`})}),(0,V.jsx)(E,{label:`Duration (minutes)`,optional:!0,children:e=>(0,V.jsx)(A,{...e,type:`number`,min:1,value:t.estimatedMinutes??``,onChange:e=>i({estimatedMinutes:e.target.value?Number(e.target.value):null})})})]})]})}case`resource`:{let r=e.settings;return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(b,{columns:2,value:r.kind,onChange:e=>i({kind:e}),options:[{value:`link`,label:`Link`,description:`Point to a web page or document.`},{value:`file`,label:`File`,description:`Upload a PDF, slides, a dataset…`}]}),r.kind===`link`?(0,V.jsx)(E,{label:`URL`,children:e=>(0,V.jsx)(A,{...e,value:r.url??``,onChange:e=>i({url:e.target.value}),placeholder:`https://`})}):(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(x,{children:`File`}),r.fileId&&a?(0,V.jsx)(O,{file:a,onRemove:()=>{o(null),i({fileId:null})}}):r.fileId?(0,V.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`A file is attached.`,` `,(0,V.jsx)(`button`,{type:`button`,className:`text-primary hover:underline`,onClick:()=>i({fileId:null}),children:`Replace it`})]}):(0,V.jsx)(C,{context:`activity`,courseId:n.id,onUploaded:n=>{o(n),t({...e,title:e.title||n.name.replace(/\.[^.]+$/,``),settings:{...r,fileId:n.id}})}})]})]})}case`assignment`:{let t=e.settings,n=(e,n)=>{let r=n?[...new Set([...t.submissionTypes,e])]:t.submissionTypes.filter(t=>t!==e);r.length&&i({submissionTypes:r})};return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,V.jsx)(E,{label:`Due date`,optional:!0,children:t=>(0,V.jsx)(A,{...t,type:`datetime-local`,value:e.dueAt,onChange:e=>r(`dueAt`,e.target.value)})}),(0,V.jsx)(E,{label:`Maximum points`,children:t=>(0,V.jsx)(A,{...t,type:`number`,min:0,value:e.maxGrade,onChange:e=>r(`maxGrade`,e.target.value)})})]}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(x,{children:`Students can submit`}),(0,V.jsx)(`div`,{className:`flex flex-wrap gap-5`,children:[`text`,`file`].map(e=>(0,V.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,V.jsx)(k,{checked:t.submissionTypes.includes(e),onCheckedChange:t=>n(e,t===!0)}),e===`text`?`Online text`:`File uploads`]},e))})]}),t.submissionTypes.includes(`file`)&&(0,V.jsx)(E,{label:`Maximum files`,className:`sm:w-48`,children:e=>(0,V.jsx)(A,{...e,type:`number`,min:1,max:20,value:t.maxFiles,onChange:e=>i({maxFiles:Number(e.target.value)||1})})}),(0,V.jsx)(D,{label:`Accept late submissions`,description:`Students can still submit after the due date; late work is flagged.`,checked:t.allowLate,onCheckedChange:e=>i({allowLate:e})})]})}case`quiz`:{let t=e.settings;return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,V.jsx)(E,{label:`Closes`,optional:!0,hint:`Students can't start attempts after this.`,children:t=>(0,V.jsx)(A,{...t,type:`datetime-local`,value:e.dueAt,onChange:e=>r(`dueAt`,e.target.value)})}),(0,V.jsx)(E,{label:`Time limit (minutes)`,optional:!0,children:e=>(0,V.jsx)(A,{...e,type:`number`,min:1,value:t.timeLimitMinutes??``,onChange:e=>i({timeLimitMinutes:e.target.value?Number(e.target.value):null}),placeholder:`No limit`})}),(0,V.jsx)(E,{label:`Attempts allowed`,children:e=>(0,V.jsxs)(S,{...e,value:t.attemptsAllowed,onChange:e=>i({attemptsAllowed:Number(e.target.value)}),children:[(0,V.jsx)(`option`,{value:0,children:`Unlimited`}),[1,2,3,4,5,10].map(e=>(0,V.jsx)(`option`,{value:e,children:e},e))]})}),(0,V.jsx)(E,{label:`Grade to keep`,children:e=>(0,V.jsxs)(S,{...e,value:t.gradingMethod,onChange:e=>i({gradingMethod:e.target.value}),children:[(0,V.jsx)(`option`,{value:`highest`,children:`Highest attempt`}),(0,V.jsx)(`option`,{value:`last`,children:`Last attempt`}),(0,V.jsx)(`option`,{value:`average`,children:`Average of attempts`})]})}),(0,V.jsx)(E,{label:`Show correct answers`,children:e=>(0,V.jsxs)(S,{...e,value:t.reviewMode,onChange:e=>i({reviewMode:e.target.value}),children:[(0,V.jsx)(`option`,{value:`immediate`,children:`Right after each attempt`}),(0,V.jsx)(`option`,{value:`after_due`,children:`After the quiz closes`}),(0,V.jsx)(`option`,{value:`score_only`,children:`Never (score only)`})]})}),(0,V.jsx)(E,{label:`Pass mark (%)`,optional:!0,children:e=>(0,V.jsx)(A,{...e,type:`number`,min:0,max:100,value:t.passingPercent??``,onChange:e=>i({passingPercent:e.target.value?Number(e.target.value):null}),placeholder:`None`})})]}),(0,V.jsx)(D,{label:`Shuffle questions`,description:`Each attempt gets the questions in a random order.`,checked:t.shuffleQuestions,onCheckedChange:e=>i({shuffleQuestions:e})})]})}case`forum`:{let t=e.settings;return(0,V.jsx)(D,{label:`Students can start discussions`,description:`Turn off for a teacher-led forum where students only reply.`,checked:t.studentsCanStartDiscussions,onCheckedChange:e=>i({studentsCanStartDiscussions:e})})}}}function K({course:t,open:r,onOpenChange:i,sectionId:l,activityId:b}){let x=g(),C=N(),O=!!b,[k,P]=(0,B.useState)(null),{data:F,isLoading:I}=n({queryKey:[`activity`,b],queryFn:()=>c.get(`/activities/${b}`),enabled:r&&O});(0,B.useEffect)(()=>{r||P(null)},[r]),(0,B.useEffect)(()=>{r&&O&&F&&!k&&P({type:F.type,title:F.title,description:F.description,visible:F.visible,completion:F.completion,dueAt:e(F.dueAt),maxGrade:F.maxGrade==null?``:String(F.maxGrade),settings:F.settings})},[r,O,F,k]);let R=v({mutationFn:async()=>{if(!k)return null;let e={title:k.title,description:k.description,visible:k.visible,completion:k.completion,settings:k.settings,...k.type===`assignment`||k.type===`quiz`?{dueAt:s(k.dueAt)}:{},...k.type===`assignment`&&k.maxGrade!==``?{maxGrade:Number(k.maxGrade)}:{}};return O?(await c.patch(`/activities/${b}`,e),{id:b}):c.post(`/courses/${t.id}/activities`,{...e,type:k.type,sectionId:l})},onSuccess:async e=>{await C(t.slug),i(!1),!O&&e&&k?.type===`quiz`?(u.success(`Quiz created. Now add some questions.`),x(`${M(t.slug,e.id)}/questions`)):u.success(O?`Changes saved`:`${p[k.type].label} added`)},onError:e=>u.error(o(e))}),z=k?.type===`assignment`?`Instructions`:k?.type===`quiz`?`Introduction`:`Description`;return(0,V.jsx)(y,{open:r,onOpenChange:i,children:(0,V.jsx)(m,{size:k?`lg`:`md`,children:k?(0,V.jsxs)(`form`,{className:`flex min-h-0 flex-1 flex-col`,onSubmit:e=>{e.preventDefault(),R.mutate()},children:[(0,V.jsx)(w,{icon:(0,V.jsx)(j,{type:k.type,className:`size-10 bg-transparent`}),title:O?`Edit ${p[k.type].label.toLowerCase()}`:`New ${p[k.type].label.toLowerCase()}`,description:L[k.type]}),(0,V.jsxs)(h,{className:`space-y-5 pb-4`,children:[(0,V.jsx)(E,{label:`Title`,children:e=>(0,V.jsx)(A,{...e,autoFocus:!0,required:!0,value:k.title,onChange:e=>P({...k,title:e.target.value})})}),k.type!==`lesson`&&(0,V.jsx)(E,{label:z,optional:k.type!==`assignment`,children:e=>(0,V.jsx)(f,{id:e.id,value:k.description,onChange:e=>P({...k,description:e}),rows:k.type===`assignment`?8:4})}),(0,V.jsx)(G,{form:k,setForm:P,course:t}),(0,V.jsxs)(`div`,{className:`grid gap-4 border-t pt-5 sm:grid-cols-2`,children:[(0,V.jsx)(E,{label:`Completion tracking`,children:e=>(0,V.jsxs)(S,{...e,value:k.completion,onChange:e=>P({...k,completion:e.target.value}),children:[(0,V.jsx)(`option`,{value:`none`,children:`Don't track`}),(0,V.jsx)(`option`,{value:`manual`,children:`Students mark it as done`}),(0,V.jsx)(`option`,{value:`auto`,children:H[k.type]})]})}),(0,V.jsx)(`div`,{className:`sm:pt-6`,children:(0,V.jsx)(D,{label:`Visible to students`,checked:k.visible,onCheckedChange:e=>P({...k,visible:e})})})]})]}),(0,V.jsxs)(_,{className:`border-t`,children:[!O&&(0,V.jsxs)(a,{type:`button`,variant:`ghost`,className:`sm:mr-auto`,onClick:()=>P(null),children:[(0,V.jsx)(T,{}),` Change type`]}),(0,V.jsx)(a,{type:`button`,variant:`outline`,onClick:()=>i(!1),children:`Cancel`}),(0,V.jsx)(a,{type:`submit`,loading:R.isPending,children:O?`Save changes`:k.type===`quiz`?`Create and add questions`:`Add ${p[k.type].label.toLowerCase()}`})]})]}):O?I?(0,V.jsx)(d,{}):(0,V.jsx)(w,{title:`Loading…`}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(w,{title:`Add an activity`,description:`Choose what you'd like to add to this section.`}),(0,V.jsx)(h,{className:`pb-6`,children:(0,V.jsx)(W,{onPick:e=>P(U(e))})})]})})})}export{z as n,K as t};
3
+ Write your lesson here…`})}),(0,V.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-[1fr_180px]`,children:[(0,V.jsx)(E,{label:`Video URL`,optional:!0,hint:`YouTube, Vimeo or a direct .mp4 link.`,children:e=>(0,V.jsx)(A,{...e,value:t.videoUrl??``,onChange:e=>i({videoUrl:e.target.value||null}),placeholder:`https://www.youtube.com/watch?v=…`})}),(0,V.jsx)(E,{label:`Duration (minutes)`,optional:!0,children:e=>(0,V.jsx)(A,{...e,type:`number`,min:1,value:t.estimatedMinutes??``,onChange:e=>i({estimatedMinutes:e.target.value?Number(e.target.value):null})})})]})]})}case`resource`:{let r=e.settings;return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(x,{columns:2,value:r.kind,onChange:e=>i({kind:e}),options:[{value:`link`,label:`Link`,description:`Point to a web page or document.`},{value:`file`,label:`File`,description:`Upload a PDF, slides, a dataset…`}]}),r.kind===`link`?(0,V.jsx)(E,{label:`URL`,children:e=>(0,V.jsx)(A,{...e,value:r.url??``,onChange:e=>i({url:e.target.value}),placeholder:`https://`})}):(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(S,{children:`File`}),r.fileId&&a?(0,V.jsx)(O,{file:a,onRemove:()=>{o(null),i({fileId:null})}}):r.fileId?(0,V.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`A file is attached.`,` `,(0,V.jsx)(`button`,{type:`button`,className:`text-primary hover:underline`,onClick:()=>i({fileId:null}),children:`Replace it`})]}):(0,V.jsx)(w,{context:`activity`,courseId:n.id,onUploaded:n=>{o(n),t({...e,title:e.title||n.name.replace(/\.[^.]+$/,``),settings:{...r,fileId:n.id}})}})]})]})}case`assignment`:{let t=e.settings,n=(e,n)=>{let r=n?[...new Set([...t.submissionTypes,e])]:t.submissionTypes.filter(t=>t!==e);r.length&&i({submissionTypes:r})};return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,V.jsx)(E,{label:`Due date`,optional:!0,children:t=>(0,V.jsx)(A,{...t,type:`datetime-local`,value:e.dueAt,onChange:e=>r(`dueAt`,e.target.value)})}),(0,V.jsx)(E,{label:`Maximum points`,children:t=>(0,V.jsx)(A,{...t,type:`number`,min:0,value:e.maxGrade,onChange:e=>r(`maxGrade`,e.target.value)})})]}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(S,{children:`Students can submit`}),(0,V.jsx)(`div`,{className:`flex flex-wrap gap-5`,children:[`text`,`file`].map(e=>(0,V.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,V.jsx)(k,{checked:t.submissionTypes.includes(e),onCheckedChange:t=>n(e,t===!0)}),e===`text`?`Online text`:`File uploads`]},e))})]}),t.submissionTypes.includes(`file`)&&(0,V.jsx)(E,{label:`Maximum files`,className:`sm:w-48`,children:e=>(0,V.jsx)(A,{...e,type:`number`,min:1,max:20,value:t.maxFiles,onChange:e=>i({maxFiles:Number(e.target.value)||1})})}),(0,V.jsx)(D,{label:`Accept late submissions`,description:`Students can still submit after the due date; late work is flagged.`,checked:t.allowLate,onCheckedChange:e=>i({allowLate:e})})]})}case`quiz`:{let t=e.settings;return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,V.jsx)(E,{label:`Closes`,optional:!0,hint:`Students can't start attempts after this.`,children:t=>(0,V.jsx)(A,{...t,type:`datetime-local`,value:e.dueAt,onChange:e=>r(`dueAt`,e.target.value)})}),(0,V.jsx)(E,{label:`Time limit (minutes)`,optional:!0,children:e=>(0,V.jsx)(A,{...e,type:`number`,min:1,value:t.timeLimitMinutes??``,onChange:e=>i({timeLimitMinutes:e.target.value?Number(e.target.value):null}),placeholder:`No limit`})}),(0,V.jsx)(E,{label:`Attempts allowed`,children:e=>(0,V.jsxs)(C,{...e,value:t.attemptsAllowed,onChange:e=>i({attemptsAllowed:Number(e.target.value)}),children:[(0,V.jsx)(`option`,{value:0,children:`Unlimited`}),[1,2,3,4,5,10].map(e=>(0,V.jsx)(`option`,{value:e,children:e},e))]})}),(0,V.jsx)(E,{label:`Grade to keep`,children:e=>(0,V.jsxs)(C,{...e,value:t.gradingMethod,onChange:e=>i({gradingMethod:e.target.value}),children:[(0,V.jsx)(`option`,{value:`highest`,children:`Highest attempt`}),(0,V.jsx)(`option`,{value:`last`,children:`Last attempt`}),(0,V.jsx)(`option`,{value:`average`,children:`Average of attempts`})]})}),(0,V.jsx)(E,{label:`Show correct answers`,children:e=>(0,V.jsxs)(C,{...e,value:t.reviewMode,onChange:e=>i({reviewMode:e.target.value}),children:[(0,V.jsx)(`option`,{value:`immediate`,children:`Right after each attempt`}),(0,V.jsx)(`option`,{value:`after_due`,children:`After the quiz closes`}),(0,V.jsx)(`option`,{value:`score_only`,children:`Never (score only)`})]})}),(0,V.jsx)(E,{label:`Pass mark (%)`,optional:!0,children:e=>(0,V.jsx)(A,{...e,type:`number`,min:0,max:100,value:t.passingPercent??``,onChange:e=>i({passingPercent:e.target.value?Number(e.target.value):null}),placeholder:`None`})})]}),(0,V.jsx)(D,{label:`Shuffle questions`,description:`Each attempt gets the questions in a random order.`,checked:t.shuffleQuestions,onCheckedChange:e=>i({shuffleQuestions:e})})]})}case`forum`:{let t=e.settings;return(0,V.jsx)(D,{label:`Students can start discussions`,description:`Turn off for a teacher-led forum where students only reply.`,checked:t.studentsCanStartDiscussions,onCheckedChange:e=>i({studentsCanStartDiscussions:e})})}}}function K({course:t,open:r,onOpenChange:i,sectionId:l,activityId:x}){let S=v(),w=N(),O=!!x,[k,P]=(0,B.useState)(null),{data:F,isLoading:I}=n({queryKey:[`activity`,x],queryFn:()=>c.get(`/activities/${x}`),enabled:r&&O});(0,B.useEffect)(()=>{r||P(null)},[r]),(0,B.useEffect)(()=>{r&&O&&F&&!k&&P({type:F.type,title:F.title,description:F.description,visible:F.visible,completion:F.completion,dueAt:e(F.dueAt),maxGrade:F.maxGrade==null?``:String(F.maxGrade),settings:F.settings})},[r,O,F,k]);let R=_({mutationFn:async()=>{if(!k)return null;let e={title:k.title,description:k.description,visible:k.visible,completion:k.completion,settings:k.settings,...k.type===`assignment`||k.type===`quiz`?{dueAt:s(k.dueAt)}:{},...k.type===`assignment`&&k.maxGrade!==``?{maxGrade:Number(k.maxGrade)}:{}};return O?(await c.patch(`/activities/${x}`,e),{id:x}):c.post(`/courses/${t.id}/activities`,{...e,type:k.type,sectionId:l})},onSuccess:async e=>{await w(t.slug),i(!1),!O&&e&&k?.type===`quiz`?(u.success(`Quiz created. Now add some questions.`),S(`${b(t.slug,e.id)}/questions`)):u.success(O?`Changes saved`:`${j[k.type].label} added`)},onError:e=>u.error(o(e))}),z=k?.type===`assignment`?`Instructions`:k?.type===`quiz`?`Introduction`:`Description`;return(0,V.jsx)(h,{open:r,onOpenChange:i,children:(0,V.jsx)(y,{size:k?`lg`:`md`,children:k?(0,V.jsxs)(`form`,{className:`flex min-h-0 flex-1 flex-col`,onSubmit:e=>{e.preventDefault(),R.mutate()},children:[(0,V.jsx)(p,{icon:(0,V.jsx)(M,{type:k.type,className:`size-10 bg-transparent`}),title:O?`Edit ${j[k.type].label.toLowerCase()}`:`New ${j[k.type].label.toLowerCase()}`,description:L[k.type]}),(0,V.jsxs)(m,{className:`space-y-5 pb-4`,children:[(0,V.jsx)(E,{label:`Title`,children:e=>(0,V.jsx)(A,{...e,autoFocus:!0,required:!0,value:k.title,onChange:e=>P({...k,title:e.target.value})})}),k.type!==`lesson`&&(0,V.jsx)(E,{label:z,optional:k.type!==`assignment`,children:e=>(0,V.jsx)(f,{id:e.id,value:k.description,onChange:e=>P({...k,description:e}),rows:k.type===`assignment`?8:4})}),(0,V.jsx)(G,{form:k,setForm:P,course:t}),(0,V.jsxs)(`div`,{className:`grid gap-4 border-t pt-5 sm:grid-cols-2`,children:[(0,V.jsx)(E,{label:`Completion tracking`,children:e=>(0,V.jsxs)(C,{...e,value:k.completion,onChange:e=>P({...k,completion:e.target.value}),children:[(0,V.jsx)(`option`,{value:`none`,children:`Don't track`}),(0,V.jsx)(`option`,{value:`manual`,children:`Students mark it as done`}),(0,V.jsx)(`option`,{value:`auto`,children:H[k.type]})]})}),(0,V.jsx)(`div`,{className:`sm:pt-6`,children:(0,V.jsx)(D,{label:`Visible to students`,checked:k.visible,onCheckedChange:e=>P({...k,visible:e})})})]})]}),(0,V.jsxs)(T,{className:`border-t`,children:[!O&&(0,V.jsxs)(a,{type:`button`,variant:`ghost`,className:`sm:mr-auto`,onClick:()=>P(null),children:[(0,V.jsx)(g,{}),` Change type`]}),(0,V.jsx)(a,{type:`button`,variant:`outline`,onClick:()=>i(!1),children:`Cancel`}),(0,V.jsx)(a,{type:`submit`,loading:R.isPending,children:O?`Save changes`:k.type===`quiz`?`Create and add questions`:`Add ${j[k.type].label.toLowerCase()}`})]})]}):O?I?(0,V.jsx)(d,{}):(0,V.jsx)(p,{title:`Loading…`}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(p,{title:`Add an activity`,description:`Choose what you'd like to add to this section.`}),(0,V.jsx)(m,{className:`pb-6`,children:(0,V.jsx)(W,{onPick:e=>P(U(e))})})]})})})}export{z as n,K as t};
@@ -0,0 +1 @@
1
+ import{t as e}from"./download-BrtK5sVk.js";import{C as t,D as n,E as r,H as i,M as a,N as o,T as s,U as c,_ as l,dt as u,ft as d,g as f,h as p,m,mt as h,n as g,p as _,r as v}from"./hooks-EFhyJ5yU.js";import{A as y,C as b,D as ee,Dt as x,E as te,Et as S,Gt as C,Ht as w,It as T,M as E,Nt as ne,O as re,T as D,Wt as ie,_ as O,d as ae,dt as oe,i as se,jt as ce,k as le,l as k,mt as ue,n as A,pt as j,r as M,rt as N,t as P,tt as F,u as de,xt as I}from"./index-CEZdqKdi.js";import{i as fe,n as L,r as R}from"./markdown-HNlXovsL.js";import{E as z,a as pe,c as B,n as V,t as H}from"./misc-CyGhN6HT.js";import me from"./NotFoundPage-BmwVsGAy.js";import{t as U}from"./clock-DPBmdKAi.js";import{t as he}from"./message-square-text-wvO9_guT.js";import{t as ge}from"./pencil-DFUpj3YP.js";import{t as _e}from"./send-BnVkFV8w.js";import{a as W}from"./context-D8W_QqNi.js";import{n as ve,t as G}from"./frame-DZh5g5b3.js";import{t as ye}from"./lock-C2edVDOc.js";import{t as be}from"./pin-DNUQ6-WX.js";import{t as K}from"./hourglass-BKca6Cje.js";import{t as xe}from"./rotate-ccw-yBj9Ri49.js";import{t as Se}from"./target-G9Q_WQLB.js";import{t as Ce}from"./trophy-BFFngFEh.js";var q={name:`circle-question-mark`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9 9.5a3 2.5 0 016 0c0 2-2 2-3 3.5`,key:`1awbb0`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]],aliases:[`help-circle`,`circle-help`]};q.node;var we=i(q),J={name:`external-link`,size:24,node:[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]};J.node;var Y=i(J),Te={name:`play`,size:24,node:[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]};Te.node;var Ee=i(Te),X=h(d(),1),Z=u();function Q({icon:e,label:t,children:n}){return(0,Z.jsxs)(`div`,{className:`flex items-start gap-3 py-3 text-sm first:pt-0 last:pb-0`,children:[(0,Z.jsx)(`span`,{className:`mt-0.5 text-muted-foreground [&_svg]:size-4`,children:e}),(0,Z.jsx)(`span`,{className:`w-24 shrink-0 text-muted-foreground`,children:t}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 font-medium`,children:n})]})}function De({dueAt:e}){let t=g(3e4),n=new Date(e).getTime()-t;if(n<=0)return(0,Z.jsx)(`span`,{className:`text-destructive`,children:`Past due`});let r=Math.floor(n/864e5),i=Math.floor(n%864e5/36e5),a=Math.floor(n%36e5/6e4);return(0,Z.jsx)(`span`,{className:l(n<864e5&&`text-amber-600 dark:text-amber-400`),children:r>0?`${r}d ${i}h left`:`${i}h ${a}m left`})}function Oe({activity:e}){let t=e.settings,r=e.submission??null,i=W(),[o,s]=(0,X.useState)(!r),[c,l]=(0,X.useState)(r?.text??``),[u,d]=(0,X.useState)(r?.files??[]),h=!!e.dueAt&&a(e.dueAt)&&!t.allowLate,g=t.submissionTypes.includes(`text`),_=t.submissionTypes.includes(`file`),v=C({mutationFn:()=>m.put(`/activities/${e.id}/submission`,{text:g?c:null,fileIds:u.map(e=>e.id)}),onSuccess:async()=>{z.success(r?`Submission updated`:`Submitted! Your teacher will review it soon.`),s(!1),await i(e.course.slug)},onError:e=>z.error(p(e))});return r&&!o?(0,Z.jsxs)(P,{children:[(0,Z.jsx)(A,{title:`Your submission`,description:(0,Z.jsxs)(`span`,{className:`flex items-center gap-2`,children:[`Submitted `,n(r.submittedAt),r.late&&(0,Z.jsx)(b,{variant:`warning`,children:`Late`})]}),icon:(0,Z.jsx)(x,{className:`size-4.5 text-success`}),action:!h&&(0,Z.jsxs)(f,{variant:`outline`,size:`sm`,onClick:()=>{l(r.text??``),d(r.files),s(!0)},children:[(0,Z.jsx)(ge,{}),` Edit submission`]})}),(0,Z.jsxs)(`div`,{className:`space-y-4 px-5 pb-5`,children:[r.text&&(0,Z.jsx)(`div`,{className:`rounded-lg border bg-muted/30 p-4`,children:(0,Z.jsx)(L,{source:r.text,className:`prose-sm`})}),r.files.length>0&&(0,Z.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:r.files.map(e=>(0,Z.jsx)(M,{file:e},e.id))})]})]}):h&&!r?(0,Z.jsxs)(P,{className:`p-6 text-center`,children:[(0,Z.jsx)(U,{className:`mx-auto size-6 text-muted-foreground`}),(0,Z.jsx)(`p`,{className:`mt-2 font-medium`,children:`Submissions are closed`}),(0,Z.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`The due date has passed and this assignment doesn't accept late work.`})]}):(0,Z.jsxs)(P,{children:[(0,Z.jsx)(A,{title:r?`Edit your submission`:`Submit your work`,description:r?`Your previous submission will be replaced.`:void 0,icon:(0,Z.jsx)(N,{className:`size-4.5`})}),(0,Z.jsxs)(`form`,{className:`space-y-5 px-5 pb-5`,onSubmit:e=>{e.preventDefault(),v.mutate()},children:[g&&(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(ae,{children:`Online text`}),(0,Z.jsx)(R,{value:c,onChange:l,rows:8,placeholder:`Write your answer, or paste a link to your work…`})]}),_&&(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsxs)(ae,{children:[`Files`,` `,(0,Z.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[`(`,u.length,`/`,t.maxFiles,`)`]})]}),u.length>0&&(0,Z.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:u.map(e=>(0,Z.jsx)(M,{file:e,onRemove:()=>d(u.filter(t=>t.id!==e.id))},e.id))}),u.length<t.maxFiles&&(0,Z.jsx)(se,{context:`submission`,courseId:e.course.id,multiple:!0,onUploaded:e=>d(n=>[...n,e].slice(0,t.maxFiles))})]}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[r&&(0,Z.jsx)(f,{type:`button`,variant:`ghost`,onClick:()=>s(!1),children:`Cancel`}),(0,Z.jsxs)(f,{type:`submit`,loading:v.isPending,disabled:!c.trim()&&u.length===0,children:[(0,Z.jsx)(_e,{}),` `,r?`Update submission`:`Submit assignment`]})]})]})]})}function ke({activity:e}){let t=e.settings,i=e.capabilities.includes(`assignment:submit`),a=e.capabilities.includes(`grades:viewAll`),o=e.grade,c=e.submissionStats,l=o?.score!=null,u=l?`Graded`:e.submission?e.submission.late?`Submitted late`:`Submitted`:`Not submitted`;return(0,Z.jsx)(G,{activity:e,children:(0,Z.jsxs)(`div`,{className:`grid items-start gap-6 lg:grid-cols-[minmax(0,1fr)_300px]`,children:[(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[l&&i&&(0,Z.jsxs)(P,{className:`overflow-hidden border-success/30`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-4 bg-success/[0.06] px-5 py-4`,children:[(0,Z.jsx)(`span`,{className:`grid size-12 place-items-center rounded-full bg-success text-white`,children:(0,Z.jsx)(x,{className:`size-6`})}),(0,Z.jsxs)(`div`,{className:`flex-1`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Your grade`}),(0,Z.jsxs)(`p`,{className:`text-2xl font-semibold tabular-nums`,children:[r(o.score),` `,(0,Z.jsxs)(`span`,{className:`text-base font-normal text-muted-foreground`,children:[`/ `,r(o.maxGrade)]})]})]}),(0,Z.jsxs)(`span`,{className:`text-2xl font-semibold text-success tabular-nums`,children:[Math.round(o.score/(o.maxGrade||1)*100),`%`]})]}),o.feedback&&(0,Z.jsxs)(`div`,{className:`flex gap-3 border-t px-5 py-4`,children:[o.gradedBy?(0,Z.jsx)(E,{user:o.gradedBy,size:`sm`}):(0,Z.jsx)(he,{className:`size-5 text-muted-foreground`}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`p`,{className:`text-sm font-medium`,children:[o.gradedBy?.name??`Feedback`,` `,(0,Z.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[`· `,n(o.gradedAt)]})]}),(0,Z.jsx)(`p`,{className:`mt-1 text-sm whitespace-pre-wrap`,children:o.feedback})]})]})]}),(0,Z.jsxs)(P,{className:`p-6 sm:p-8`,children:[(0,Z.jsxs)(`h2`,{className:`mb-3 flex items-center gap-2 text-sm font-semibold text-muted-foreground`,children:[(0,Z.jsx)(I,{className:`size-4`}),` Instructions`]}),e.description.trim()?(0,Z.jsx)(L,{source:e.description}):(0,Z.jsx)(`p`,{className:`text-muted-foreground`,children:`No instructions provided.`})]}),i&&(0,Z.jsx)(Oe,{activity:e})]}),(0,Z.jsxs)(`div`,{className:`space-y-5 lg:sticky lg:top-20`,children:[i&&(0,Z.jsxs)(P,{className:`p-5`,children:[(0,Z.jsx)(Q,{icon:(0,Z.jsx)(ce,{}),label:`Due`,children:e.dueAt?s(e.dueAt):`No due date`}),e.dueAt&&!e.submission&&(0,Z.jsx)(Q,{icon:(0,Z.jsx)(U,{}),label:`Time left`,children:(0,Z.jsx)(De,{dueAt:e.dueAt})}),(0,Z.jsx)(Q,{icon:(0,Z.jsx)(N,{}),label:`Status`,children:(0,Z.jsx)(b,{variant:l?`success`:e.submission?`info`:`neutral`,children:u})}),(0,Z.jsx)(Q,{icon:(0,Z.jsx)(S,{}),label:`Grade`,children:l?`${r(o.score)} / ${r(o.maxGrade)}`:(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`Not graded yet`})}),(0,Z.jsxs)(`div`,{className:`mt-3 border-t pt-3 text-xs text-muted-foreground`,children:[`Accepts`,` `,t.submissionTypes.map(e=>e===`text`?`online text`:`up to ${t.maxFiles} files`).join(` and `),`.`,t.allowLate?` Late work is accepted.`:` Late work is not accepted.`]})]}),a&&c&&(0,Z.jsxs)(P,{className:`p-5`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-semibold`,children:`Submissions`}),(0,Z.jsx)(`div`,{className:`mt-4 grid grid-cols-3 gap-2 text-center`,children:[[`Students`,c.participants],[`Submitted`,c.submitted],[`To grade`,c.needsGrading]].map(([e,t])=>(0,Z.jsxs)(`div`,{className:`rounded-lg bg-muted/60 px-2 py-3`,children:[(0,Z.jsx)(`p`,{className:`text-xl font-semibold tabular-nums`,children:t}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:e})]},e))}),(0,Z.jsx)(pe,{value:c.participants?c.submitted/c.participants*100:0,className:`mt-4`}),(0,Z.jsx)(f,{asChild:!0,className:`mt-4 w-full`,children:(0,Z.jsxs)(T,{to:`${D(e.course.slug,e.id)}/submissions`,children:[(0,Z.jsx)(F,{}),` `,c.needsGrading?`Grade ${c.needsGrading} submission${c.needsGrading===1?``:`s`}`:`View submissions`]})})]})]})]})})}function Ae({activity:e,open:t,onOpenChange:n}){let[r,i]=(0,X.useState)(``),[a,o]=(0,X.useState)(``),s=w(),c=W(),l=C({mutationFn:()=>m.post(`/activities/${e.id}/discussions`,{title:r,body:a}),onSuccess:async t=>{await c(e.course.slug),n(!1),s(`/courses/${e.course.slug}/discussions/${t.id}`)},onError:e=>z.error(p(e))});return(0,Z.jsx)(te,{open:t,onOpenChange:n,children:(0,Z.jsx)(re,{size:`lg`,children:(0,Z.jsxs)(`form`,{className:`flex min-h-0 flex-1 flex-col`,onSubmit:e=>{e.preventDefault(),l.mutate()},children:[(0,Z.jsx)(y,{icon:(0,Z.jsx)(j,{className:`size-5`}),title:`Start a discussion`,description:`Post in ${e.title}.`}),(0,Z.jsxs)(ee,{className:`space-y-4`,children:[(0,Z.jsx)(k,{label:`Subject`,children:e=>(0,Z.jsx)(de,{...e,autoFocus:!0,required:!0,value:r,onChange:e=>i(e.target.value),placeholder:`What's this about?`})}),(0,Z.jsx)(k,{label:`Message`,children:e=>(0,Z.jsx)(R,{id:e.id,value:a,onChange:o,rows:8})})]}),(0,Z.jsxs)(le,{children:[(0,Z.jsx)(f,{type:`button`,variant:`outline`,onClick:()=>n(!1),children:`Cancel`}),(0,Z.jsx)(f,{type:`submit`,loading:l.isPending,disabled:!r.trim()||!a.trim(),children:`Post discussion`})]})]})})})}function je({activity:e}){let t=e.settings,[r,i]=(0,X.useState)(!1),a=e.capabilities.includes(`forum:post`)&&(e.capabilities.includes(`forum:moderate`)||t.studentsCanStartDiscussions),{data:o,isLoading:s,error:l,refetch:u}=c({queryKey:[`discussions`,e.id],queryFn:()=>m.get(`/activities/${e.id}/discussions`)});return(0,Z.jsxs)(G,{activity:e,actions:a&&(0,Z.jsxs)(f,{onClick:()=>i(!0),children:[(0,Z.jsx)(oe,{}),` New discussion`]}),children:[e.description&&(0,Z.jsx)(P,{className:`mb-6 p-5`,children:(0,Z.jsx)(L,{source:e.description,className:`prose-sm`})}),l?(0,Z.jsx)(V,{error:l,onRetry:()=>u()}):s?(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(B,{className:`h-24`}),(0,Z.jsx)(B,{className:`h-24`})]}):o.length===0?(0,Z.jsx)(H,{icon:j,title:`No discussions yet`,description:a?`Be the first to start a conversation.`:`Discussions started by your teachers will appear here.`,action:a&&(0,Z.jsxs)(f,{onClick:()=>i(!0),children:[(0,Z.jsx)(oe,{}),` Start a discussion`]})}):(0,Z.jsx)(`div`,{className:`space-y-3`,children:o.map(t=>(0,Z.jsxs)(T,{to:`/courses/${e.course.slug}/discussions/${t.id}`,className:`group flex gap-4 rounded-xl border bg-card p-5 shadow-xs transition-all hover:border-primary/30 hover:shadow-md`,children:[(0,Z.jsx)(E,{user:t.author}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`h3`,{className:`font-semibold tracking-tight group-hover:text-primary`,children:t.title}),t.pinned&&(0,Z.jsxs)(b,{variant:`warning`,children:[(0,Z.jsx)(be,{}),` Pinned`]}),t.locked&&(0,Z.jsxs)(b,{variant:`neutral`,children:[(0,Z.jsx)(ye,{}),` Locked`]})]}),(0,Z.jsx)(`p`,{className:`mt-1 line-clamp-2 text-sm text-muted-foreground`,children:t.excerpt}),(0,Z.jsxs)(`p`,{className:`mt-2.5 text-xs text-muted-foreground`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-foreground`,children:t.author.name}),` · started `,n(t.createdAt),t.replyCount>0&&` · last reply ${n(t.lastPostAt)}`]})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 flex-col items-center justify-center rounded-lg bg-muted/60 px-3 text-center`,children:[(0,Z.jsx)(ue,{className:`size-4 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`mt-0.5 text-sm font-semibold tabular-nums`,children:t.replyCount})]})]},t.id))}),(0,Z.jsx)(Ae,{activity:e,open:r,onOpenChange:i})]})}function Me({activity:e}){let{data:t,isLoading:r,error:i,refetch:a}=c({queryKey:[`grading`,e.id],queryFn:()=>m.get(`/activities/${e.id}/grading`)});return(0,Z.jsxs)(P,{className:`border-amber-500/30`,children:[(0,Z.jsx)(A,{title:`Needs grading`,description:`Attempts with written answers waiting for a mark, oldest first.`,icon:(0,Z.jsx)(S,{className:`size-4.5`}),action:t&&(0,Z.jsx)(b,{variant:`warning`,children:t.length})}),i?(0,Z.jsx)(`div`,{className:`px-5 pb-5`,children:(0,Z.jsx)(V,{error:i,onRetry:()=>a()})}):r||!t?(0,Z.jsxs)(`div`,{className:`space-y-2 px-5 pb-5`,children:[(0,Z.jsx)(B,{className:`h-10`}),(0,Z.jsx)(B,{className:`h-10`})]}):t.length===0?(0,Z.jsx)(`p`,{className:`px-5 pb-5 text-sm text-muted-foreground`,children:`Everything is marked.`}):(0,Z.jsx)(`div`,{className:`divide-y border-t`,children:t.slice(0,50).map(t=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 px-5 py-2.5 text-sm`,children:[(0,Z.jsx)(E,{user:t.user,size:`sm`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block truncate font-medium`,children:t.user.name}),(0,Z.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[`Attempt `,t.attemptNumber,` · handed in `,n(t.finishedAt),` · `,o(t.pending,`answer`),` to mark`]})]}),(0,Z.jsx)(f,{asChild:!0,size:`sm`,variant:`outline`,children:(0,Z.jsx)(T,{to:`/courses/${e.course.slug}/attempts/${t.attemptId}`,"aria-label":`Mark ${t.user.name}'s attempt ${t.attemptNumber}`,children:`Mark`})})]},t.attemptId))})]})}function $({icon:e,label:t,value:n}){return(0,Z.jsxs)(`div`,{className:`rounded-xl border bg-card p-4`,children:[(0,Z.jsx)(e,{className:`size-4 text-muted-foreground`}),(0,Z.jsx)(`p`,{className:`mt-2 text-lg font-semibold tabular-nums`,children:n}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t})]})}var Ne={highest:`Highest attempt counts`,last:`Last attempt counts`,average:`Average of attempts`};function Pe({activity:e}){let t=w(),i=e.quiz,o=e.settings,l=e.capabilities.includes(`course:manageContent`),u=e.capabilities.includes(`quiz:viewAllAttempts`),d=i.attempts.filter(e=>e.status!==`in_progress`),h=o.attemptsAllowed?Math.max(0,o.attemptsAllowed-d.length):null,g=!!e.dueAt&&a(e.dueAt),_=C({mutationFn:()=>m.post(`/activities/${e.id}/attempts`),onSuccess:n=>t(`/courses/${e.course.slug}/attempts/${n.id}`),onError:e=>z.error(p(e))}),{data:v}=c({queryKey:[`attempts`,e.id,`all`],queryFn:()=>m.get(`/activities/${e.id}/attempts?all=1`),enabled:u}),y=i.questionCount===0?`This quiz has no questions yet.`:g?`This quiz has closed.`:h===0?`You've used all of your attempts.`:null;return(0,Z.jsx)(G,{activity:e,actions:l&&(0,Z.jsx)(f,{asChild:!0,variant:`outline`,children:(0,Z.jsxs)(T,{to:`${D(e.course.slug,e.id)}/questions`,children:[(0,Z.jsx)(fe,{}),` Questions`]})}),children:(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 md:grid-cols-4`,children:[(0,Z.jsx)($,{icon:we,label:`Questions`,value:String(i.questionCount)}),(0,Z.jsx)($,{icon:Se,label:`Points`,value:r(i.totalPoints)}),(0,Z.jsx)($,{icon:U,label:`Time limit`,value:o.timeLimitMinutes?`${o.timeLimitMinutes} min`:`None`}),(0,Z.jsx)($,{icon:xe,label:`Attempts`,value:o.attemptsAllowed?`${d.length} / ${o.attemptsAllowed}`:`${d.length} / ∞`})]}),(0,Z.jsxs)(P,{className:`overflow-hidden`,children:[e.description&&(0,Z.jsx)(`div`,{className:`border-b p-6`,children:(0,Z.jsx)(L,{source:e.description})}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4 p-6 sm:flex-row sm:items-center`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 space-y-1 text-sm text-muted-foreground`,children:[(0,Z.jsxs)(`p`,{children:[Ne[o.gradingMethod],`.`]}),e.dueAt&&(0,Z.jsxs)(`p`,{children:[g?`Closed`:`Closes`,` `,s(e.dueAt),`.`]}),o.passingPercent!=null&&(0,Z.jsxs)(`p`,{children:[`You need `,o.passingPercent,`% to pass.`]}),o.reviewMode!==`immediate`&&(0,Z.jsx)(`p`,{children:o.reviewMode===`after_due`?`Correct answers are shown after the quiz closes.`:`Only your score is shown after each attempt.`})]}),i.inProgressAttemptId?(0,Z.jsxs)(f,{size:`lg`,onClick:()=>t(`/courses/${e.course.slug}/attempts/${i.inProgressAttemptId}`),children:[(0,Z.jsx)(Ee,{}),` Continue attempt`]}):i.canAttempt?(0,Z.jsxs)(f,{size:`lg`,onClick:()=>_.mutate(),loading:_.isPending,children:[(0,Z.jsx)(Ee,{}),` `,l?`Preview quiz`:d.length?`Try again`:`Start quiz`]}):(0,Z.jsx)(`p`,{className:`rounded-lg bg-muted px-4 py-2.5 text-sm text-muted-foreground`,children:y??`You cannot attempt this quiz.`})]})]}),e.grade?.score!=null&&e.myRole===`student`&&(0,Z.jsxs)(P,{className:`flex items-center gap-4 p-5`,children:[(0,Z.jsx)(`span`,{className:`grid size-11 place-items-center rounded-full bg-amber-500/15 text-amber-600 dark:text-amber-400`,children:(0,Z.jsx)(Ce,{className:`size-5`})}),(0,Z.jsxs)(`div`,{className:`flex-1`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Your grade for this quiz`}),(0,Z.jsxs)(`p`,{className:`text-xl font-semibold tabular-nums`,children:[r(e.grade.score),` `,(0,Z.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`/ `,r(e.grade.maxGrade)]})]})]}),(0,Z.jsxs)(b,{variant:`success`,children:[Math.round(e.grade.score/(e.grade.maxGrade||1)*100),`%`]})]}),i.attempts.length>0&&(0,Z.jsxs)(P,{children:[(0,Z.jsx)(A,{title:l?`Your previews`:`Your attempts`,icon:(0,Z.jsx)(ne,{className:`size-4.5`})}),(0,Z.jsx)(`div`,{className:`divide-y border-t`,children:i.attempts.map(t=>(0,Z.jsxs)(T,{to:`/courses/${e.course.slug}/attempts/${t.id}`,className:`flex items-center gap-4 px-5 py-3 text-sm transition-colors hover:bg-accent/40`,children:[(0,Z.jsx)(`span`,{className:`grid size-8 place-items-center rounded-full bg-muted text-xs font-semibold`,children:t.attemptNumber}),(0,Z.jsxs)(`span`,{className:`flex-1`,children:[(0,Z.jsxs)(`span`,{className:`block font-medium`,children:[`Attempt `,t.attemptNumber]}),(0,Z.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:t.status===`in_progress`?`Started ${n(t.startedAt)}`:`Finished ${n(t.finishedAt)}`})]}),t.status===`needs_grading`?(0,Z.jsxs)(b,{variant:`warning`,children:[(0,Z.jsx)(K,{}),` Waiting for grading`]}):t.status===`finished`?(0,Z.jsxs)(`span`,{className:`text-right`,children:[(0,Z.jsxs)(`span`,{className:`block font-semibold tabular-nums`,children:[r(t.score),` / `,r(t.maxScore)]}),(0,Z.jsxs)(`span`,{className:`block text-xs text-muted-foreground tabular-nums`,children:[t.maxScore?Math.round((t.score??0)/t.maxScore*100):0,`%`]})]}):(0,Z.jsx)(b,{variant:`info`,children:`In progress`})]},t.id))})]}),u&&!!i.needsGrading&&(0,Z.jsx)(Me,{activity:e}),u&&(0,Z.jsxs)(P,{children:[(0,Z.jsx)(A,{title:`Student attempts`,description:`Every attempt, newest first.`,icon:(0,Z.jsx)(F,{className:`size-4.5`})}),v&&v.filter(e=>e.status!==`in_progress`).length>0?(0,Z.jsx)(`div`,{className:`divide-y border-t`,children:v.filter(e=>e.status!==`in_progress`).slice(0,50).map(t=>(0,Z.jsxs)(T,{to:`/courses/${e.course.slug}/attempts/${t.id}`,className:`flex items-center gap-3 px-5 py-2.5 text-sm hover:bg-accent/40`,children:[t.user&&(0,Z.jsx)(E,{user:t.user,size:`sm`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block truncate font-medium`,children:t.user?.name}),(0,Z.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[`Attempt `,t.attemptNumber,` · `,n(t.finishedAt)]})]}),t.status===`needs_grading`?(0,Z.jsxs)(b,{variant:`warning`,children:[(0,Z.jsx)(K,{}),` Needs grading`]}):(0,Z.jsxs)(`span`,{className:`font-semibold tabular-nums`,children:[r(t.score),` / `,r(t.maxScore)]})]},t.id))}):(0,Z.jsx)(`div`,{className:`px-5 pb-5`,children:(0,Z.jsx)(H,{icon:F,title:`No attempts yet`,className:`py-8`})})]})]})})}function Fe(e){let t=e.match(/(?:youtube\.com\/(?:watch\?(?:.*&)?v=|embed\/|shorts\/)|youtu\.be\/)([\w-]{11})/);if(t)return{kind:`iframe`,src:`https://www.youtube-nocookie.com/embed/${t[1]}`};let n=e.match(/vimeo\.com\/(?:video\/)?(\d+)/);return n?{kind:`iframe`,src:`https://player.vimeo.com/video/${n[1]}`}:/\.(mp4|webm|ogg)(\?|$)/i.test(e)?{kind:`video`,src:e}:{kind:`link`,src:e}}function Ie({activity:e}){let t=e.settings,n=t.videoUrl?Fe(t.videoUrl):null;return(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[n&&n.kind!==`link`&&(0,Z.jsx)(`div`,{className:`overflow-hidden rounded-2xl border bg-black shadow-lg`,children:n.kind===`iframe`?(0,Z.jsx)(`iframe`,{src:n.src,title:e.title,className:`aspect-video w-full`,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture`,allowFullScreen:!0}):(0,Z.jsx)(`video`,{src:n.src,controls:!0,className:`aspect-video w-full`})}),n?.kind===`link`&&(0,Z.jsxs)(`a`,{href:n.src,target:`_blank`,rel:`noreferrer`,className:`flex items-center gap-2 text-sm font-medium text-primary hover:underline`,children:[(0,Z.jsx)(Y,{className:`size-4`}),` Watch the video`]}),(0,Z.jsx)(P,{className:`px-6 py-8 sm:px-10 sm:py-10`,children:t.body.trim()?(0,Z.jsx)(L,{source:t.body,className:`mx-auto max-w-3xl`}):(0,Z.jsx)(`p`,{className:`text-muted-foreground`,children:`This lesson has no content yet.`})})]})}function Le({activity:n}){let r=n.settings,i=n.file;return(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[n.description&&(0,Z.jsx)(P,{className:`p-6`,children:(0,Z.jsx)(L,{source:n.description})}),r.kind===`link`&&r.url?(0,Z.jsxs)(P,{className:`flex flex-col gap-4 p-6 sm:flex-row sm:items-center`,children:[(0,Z.jsx)(`span`,{className:`grid size-12 shrink-0 place-items-center rounded-xl bg-slate-500/10 text-slate-600 dark:text-slate-300`,children:(0,Z.jsx)(Y,{className:`size-5`})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`p`,{className:`font-medium`,children:new URL(r.url).hostname.replace(/^www\./,``)}),(0,Z.jsx)(`p`,{className:`truncate text-sm text-muted-foreground`,children:r.url})]}),(0,Z.jsx)(f,{asChild:!0,children:(0,Z.jsxs)(`a`,{href:r.url,target:`_blank`,rel:`noopener noreferrer`,children:[`Open link `,(0,Z.jsx)(Y,{})]})})]}):i?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(P,{className:`flex flex-col gap-4 p-6 sm:flex-row sm:items-center`,children:[(0,Z.jsx)(`span`,{className:`grid size-12 shrink-0 place-items-center rounded-xl bg-primary/10 text-primary`,children:(0,Z.jsx)(I,{className:`size-5`})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`p`,{className:`truncate font-medium`,children:i.name}),(0,Z.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[t(i.size),` · `,i.mime]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(f,{asChild:!0,variant:`outline`,children:(0,Z.jsxs)(`a`,{href:i.url,target:`_blank`,rel:`noreferrer`,children:[`Open `,(0,Z.jsx)(Y,{})]})}),(0,Z.jsx)(f,{asChild:!0,children:(0,Z.jsxs)(`a`,{href:`${i.url}?download=1`,children:[(0,Z.jsx)(e,{}),` Download`]})})]})]}),i.mime.startsWith(`image/`)&&(0,Z.jsx)(`img`,{src:i.url,alt:i.name,className:`max-h-[70vh] rounded-xl border object-contain`}),i.mime===`application/pdf`&&(0,Z.jsx)(`iframe`,{src:i.url,title:i.name,className:`h-[75vh] w-full rounded-xl border bg-white`}),i.mime.startsWith(`video/`)&&(0,Z.jsx)(`video`,{src:i.url,controls:!0,className:`w-full rounded-xl border`})]}):(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The file for this resource is missing.`})]})}function Re(){let{activityId:e}=ie(),{data:t,isLoading:n,error:r,refetch:i}=ve(e);if(v(t?.title),n)return(0,Z.jsxs)(O,{className:`max-w-5xl`,children:[(0,Z.jsx)(B,{className:`mb-6 h-16`}),(0,Z.jsx)(B,{className:`h-96`})]});if(r instanceof _&&r.status===404)return(0,Z.jsx)(me,{});if(r||!t)return(0,Z.jsx)(O,{children:(0,Z.jsx)(V,{error:r,onRetry:()=>i()})});switch(t.type){case`lesson`:return(0,Z.jsx)(G,{activity:t,children:(0,Z.jsx)(Ie,{activity:t})});case`resource`:return(0,Z.jsx)(G,{activity:t,children:(0,Z.jsx)(Le,{activity:t})});case`assignment`:return(0,Z.jsx)(ke,{activity:t});case`quiz`:return(0,Z.jsx)(Pe,{activity:t});case`forum`:return(0,Z.jsx)(je,{activity:t})}}export{Re as default};
@@ -0,0 +1 @@
1
+ import{$ as e,Gt as t,H as n,J as r,V as i,at as a,dt as o,gt as s,z as c}from"./index-CEZdqKdi.js";import{U as l,dt as u,ft as d,g as f,h as p,m,mt as h,r as g,ut as _}from"./hooks-EFhyJ5yU.js";import{t as v}from"./ellipsis-BDmYLoyn.js";import{t as y}from"./pencil-DFUpj3YP.js";import{E as b,n as x,t as S}from"./misc-CyGhN6HT.js";import{n as C,t as w}from"./badge-card-ByT0wR6q.js";import{t as T}from"./badge-dialog-p2zTk4h0.js";import{t as E}from"./achievements-DaIfUTKU.js";var D=h(d(),1),O=u();function k(){g(`Site badges`);let u=_(),d=e(),[h,k]=(0,D.useState)(null),{data:A,isLoading:j,error:M,refetch:N}=l({queryKey:E.siteBadges,queryFn:()=>m.get(`/badges`)}),P=()=>u.invalidateQueries({queryKey:E.siteBadges}),F=t({mutationFn:e=>m.delete(`/badges/${e}`),onSuccess:async()=>{b.success(`Badge deleted`),await P()},onError:e=>b.error(p(e))});return(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{className:`mb-5 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,O.jsx)(`p`,{className:`max-w-2xl text-sm text-muted-foreground`,children:`Site badges recognise achievements across courses: award them by hand, or automatically when someone completes a set of courses. Teachers make course badges on each course’s Badges tab.`}),(0,O.jsxs)(f,{onClick:()=>k(`new`),className:`shrink-0`,children:[(0,O.jsx)(o,{}),` New site badge`]})]}),M?(0,O.jsx)(x,{error:M,onRetry:()=>N()}):j||!A?(0,O.jsx)(C,{}):A.length===0?(0,O.jsx)(S,{icon:s,title:`No site badges yet`,description:`Create one for community helpers, early adopters or people who finish a learning path.`,action:(0,O.jsxs)(f,{onClick:()=>k(`new`),children:[(0,O.jsx)(o,{}),` Create a site badge`]})}):(0,O.jsx)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`,children:A.map(e=>(0,O.jsx)(w,{badge:e,staff:!0,actions:(0,O.jsxs)(c,{children:[(0,O.jsx)(r,{asChild:!0,children:(0,O.jsx)(f,{variant:`ghost`,size:`icon-sm`,"aria-label":`Actions for ${e.name}`,children:(0,O.jsx)(v,{})})}),(0,O.jsxs)(i,{children:[(0,O.jsxs)(n,{onSelect:()=>k(e),children:[(0,O.jsx)(y,{}),` Edit`]}),(0,O.jsxs)(n,{destructive:!0,onSelect:async()=>{await d({title:`Delete “${e.name}”?`,description:`It is taken away from ${e.recipientCount??0} ${e.recipientCount===1?`person`:`people`}. This cannot be undone.`,confirmLabel:`Delete badge`,destructive:!0})&&F.mutate(e.id)},children:[(0,O.jsx)(a,{}),` Delete`]})]})]})},e.id))}),h&&(0,O.jsx)(T,{open:!!h,onOpenChange:e=>!e&&k(null),scope:{kind:`site`},badge:h===`new`?void 0:h,onSaved:()=>void P()})]})}export{k as default};
@@ -0,0 +1,3 @@
1
+ import{D as e,H as t,N as n,Q as r,U as i,_ as a,dt as o,ft as s,g as c,h as l,m as u,mt as d,p as f,r as p,t as m,u as h,ut as g}from"./hooks-EFhyJ5yU.js";import{$ as _,A as v,C as y,D as b,E as x,Ft as S,Gt as C,Ht as w,I as T,It as E,M as D,O,Ot as k,Wt as ee,at as A,dt as te,et as ne,k as j,kt as re,l as M,lt as ie,m as N,n as ae,nt as P,s as oe,t as F,u as se,vt as ce}from"./index-CEZdqKdi.js";import{t as le}from"./chevron-left-Bu6IJANV.js";import{t as I}from"./contact-NCWQa7wc.js";import{a as ue,i as de,t as fe}from"./cohorts-DL0Dsxva.js";import{t as L}from"./pencil-DFUpj3YP.js";import{t as pe}from"./user-minus-CkOPT3ak.js";import{t as me}from"./users-round-CNhv0Whm.js";import{E as R,c as z,l as B,n as V,t as H}from"./misc-CyGhN6HT.js";var U={name:`clipboard-paste`,size:24,node:[[`path`,{d:`M11 14h10`,key:`1w8e9d`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v1.344`,key:`1e62lh`}],[`path`,{d:`m17 18 4-4-4-4`,key:`z2g111`}],[`path`,{d:`M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113`,key:`bjbb7m`}],[`rect`,{x:`8`,y:`2`,width:`8`,height:`4`,rx:`1`,key:`ublpy`}]]};U.node;var W=t(U),G=d(s(),1),K=o(),q=20,J=1e3,Y=e=>n(e,`person`,`people`),X=e=>new URLSearchParams(Object.entries(e).flatMap(([e,t])=>t===void 0||t===``?[]:[[e,String(t)]])).toString();function Z({value:e,onChange:t,label:n,className:r,autoFocus:i}){return(0,K.jsxs)(`div`,{className:a(`relative`,r),children:[(0,K.jsx)(ie,{className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground`}),(0,K.jsx)(se,{value:e,onChange:e=>t(e.target.value),placeholder:n,"aria-label":n,className:`pl-9`,autoFocus:i})]})}function Q({page:e,pages:t,onPage:n}){return t<=1?null:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(c,{variant:`outline`,size:`icon-sm`,disabled:e<=1,onClick:()=>n(e-1),"aria-label":`Previous page`,children:(0,K.jsx)(le,{})}),(0,K.jsxs)(`span`,{className:`tabular-nums`,children:[e,` / `,t]}),(0,K.jsx)(c,{variant:`outline`,size:`icon-sm`,disabled:e>=t,onClick:()=>n(e+1),"aria-label":`Next page`,children:(0,K.jsx)(k,{})})]})}function he(){let e=g();return()=>Promise.all([e.invalidateQueries({queryKey:[`admin`,`cohorts`]}),e.invalidateQueries({queryKey:[`admin`,`cohort`]}),e.invalidateQueries({queryKey:[`cohort-links`]}),e.invalidateQueries({queryKey:[`participants`]})])}function ge({cohort:e,open:t,onOpenChange:n,onSaved:r}){let[i,a]=(0,G.useState)(e?.name??``),[o,s]=(0,G.useState)(e?.description??``),d=C({mutationFn:()=>e?u.patch(`/admin/cohorts/${e.id}`,{name:i,description:o}):u.post(`/admin/cohorts`,{name:i,description:o}),onSuccess:async t=>{R.success(e?`Cohort saved`:`Created ${t.name}`),n(!1),await r(t)},onError:e=>R.error(l(e))});return(0,K.jsx)(x,{open:t,onOpenChange:n,children:(0,K.jsx)(O,{children:(0,K.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),d.mutate()},children:[(0,K.jsx)(v,{icon:(0,K.jsx)(I,{className:`size-5`}),title:e?`Edit cohort`:`New cohort`,description:e?void 0:`A site-wide group of people, such as a year group or a department. Link it to courses to enrol everyone in it.`}),(0,K.jsxs)(b,{className:`space-y-4`,children:[(0,K.jsx)(M,{label:`Name`,children:e=>(0,K.jsx)(se,{...e,autoFocus:!0,required:!0,maxLength:100,value:i,onChange:e=>a(e.target.value),placeholder:`Class of 2027`})}),(0,K.jsx)(M,{label:`Description`,optional:!0,children:e=>(0,K.jsx)(N,{...e,rows:3,maxLength:1e3,value:o,onChange:e=>s(e.target.value)})})]}),(0,K.jsxs)(j,{children:[(0,K.jsx)(c,{type:`button`,variant:`outline`,onClick:()=>n(!1),children:`Cancel`}),(0,K.jsx)(c,{type:`submit`,loading:d.isPending,disabled:!i.trim(),children:e?`Save`:`Create cohort`})]})]})})})}function _e(){p(`Cohorts`);let e=w(),t=_(),a=he(),[o,s]=(0,G.useState)(``),[d,f]=(0,G.useState)(1),[h,g]=(0,G.useState)(null),v=m(o.trim(),300),{data:b,isLoading:x,error:S,refetch:T}=i({queryKey:[`admin`,`cohorts`,v,d],queryFn:()=>u.get(`/admin/cohorts?${X({q:v,page:d,pageSize:q})}`),placeholderData:r}),D=C({mutationFn:e=>u.delete(`/admin/cohorts/${e.id}`),onSuccess:async(e,t)=>{await a(),R.success(`Deleted ${t.name}`)},onError:e=>R.error(l(e))}),O=b?Math.max(1,Math.ceil(b.total/q)):1;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`mb-5 flex flex-col gap-3 sm:flex-row sm:items-center`,children:[(0,K.jsx)(Z,{value:o,onChange:e=>{s(e),f(1)},label:`Search cohorts`,className:`sm:w-80`}),(0,K.jsx)(`p`,{className:`hidden text-sm text-muted-foreground lg:block`,children:`Site-wide groups of people. Link one to a course to enrol everyone in it.`}),(0,K.jsxs)(c,{className:`sm:ml-auto`,onClick:()=>g(`new`),children:[(0,K.jsx)(te,{}),` New cohort`]})]}),S?(0,K.jsx)(V,{error:S,onRetry:()=>T()}):x||!b?(0,K.jsx)(z,{className:`h-64`}):b.items.length===0?(0,K.jsx)(H,{icon:I,title:v?`No cohorts found`:`No cohorts yet`,description:v?`Try another name.`:`Cohorts are site-wide groups of people, such as a year group or a department. Link a cohort to a course to enrol all its members, including people who join later.`,action:!v&&(0,K.jsxs)(c,{onClick:()=>g(`new`),children:[(0,K.jsx)(te,{}),` New cohort`]})}):(0,K.jsxs)(F,{className:`overflow-hidden`,children:[(0,K.jsx)(`ul`,{className:`divide-y`,children:b.items.map(e=>(0,K.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-3.5 sm:gap-4 sm:px-5`,children:[(0,K.jsx)(`span`,{className:`grid size-10 shrink-0 place-items-center rounded-xl bg-primary/10 text-primary`,"aria-hidden":!0,children:(0,K.jsx)(I,{className:`size-4.5`})}),(0,K.jsxs)(E,{to:`/admin/cohorts/${e.id}`,className:`group min-w-0 flex-1`,children:[(0,K.jsx)(`span`,{className:`block truncate font-medium group-hover:text-primary`,children:e.name}),(0,K.jsx)(`span`,{className:`block truncate text-sm text-muted-foreground`,children:e.description||`No description`}),(0,K.jsxs)(`span`,{className:`mt-0.5 block text-xs text-muted-foreground sm:hidden`,children:[n(e.memberCount,`member`),` · `,e.courseCount?`linked to ${n(e.courseCount,`course`)}`:`not linked`]})]}),(0,K.jsxs)(`span`,{className:`hidden shrink-0 items-center gap-1.5 sm:flex`,children:[(0,K.jsx)(y,{variant:`neutral`,children:n(e.memberCount,`member`)}),(0,K.jsx)(y,{variant:e.courseCount?`info`:`outline`,children:e.courseCount?`Linked to ${n(e.courseCount,`course`)}`:`Not linked`})]}),(0,K.jsx)(c,{variant:`ghost`,size:`icon-sm`,onClick:()=>g(e),"aria-label":`Edit ${e.name}`,children:(0,K.jsx)(L,{})}),(0,K.jsx)(c,{variant:`ghost`,size:`icon-sm`,"aria-label":`Delete ${e.name}`,onClick:async()=>{await t({title:`Delete “${e.name}”?`,description:`The cohort and its course links are removed. Everyone it enrolled stays enrolled in those courses.`,confirmLabel:`Delete cohort`,destructive:!0})&&D.mutate(e)},children:(0,K.jsx)(A,{})})]},e.id))}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-t px-5 py-3 text-sm text-muted-foreground`,children:[(0,K.jsx)(`span`,{children:n(b.total,`cohort`)}),(0,K.jsx)(Q,{page:d,pages:O,onPage:f})]})]}),h&&(0,K.jsx)(ge,{cohort:h===`new`?void 0:h,open:!!h,onOpenChange:e=>!e&&g(null),onSaved:async t=>{await a(),h===`new`&&e(`/admin/cohorts/${t.id}`)}})]})}function ve(e,t){e.added?R.success(`Added ${Y(e.added)} to ${t}`,{description:e.enrolled?`${n(e.enrolled,`new course enrolment`)} through linked courses.`:void 0}):R.info(`No one new was added`)}function ye({cohort:e,open:t,onOpenChange:o,onAdded:s}){let[d,f]=(0,G.useState)(``),p=m(d.trim(),250),[h,g]=(0,G.useState)(()=>new Map),{data:_,isFetching:S}=i({queryKey:[`admin`,`cohort`,e.id,`candidates`,p],queryFn:()=>u.get(`/admin/cohorts/${e.id}/candidates?${X({q:p})}`),enabled:t&&p.length>0,placeholderData:r}),w=(e,t)=>g(n=>{let r=new Map(n);return t?r.set(e.id,e):r.delete(e.id),r}),T=C({mutationFn:()=>u.post(`/admin/cohorts/${e.id}/members`,{userIds:[...h.keys()]}),onSuccess:async t=>{ve(t,e.name),g(new Map),f(``),o(!1),await s()},onError:e=>R.error(l(e))});return(0,K.jsx)(x,{open:t,onOpenChange:o,children:(0,K.jsx)(O,{size:`lg`,children:(0,K.jsxs)(`form`,{className:`flex min-h-0 flex-1 flex-col`,onSubmit:e=>{e.preventDefault(),h.size&&T.mutate()},children:[(0,K.jsx)(v,{icon:(0,K.jsx)(P,{className:`size-5`}),title:`Add people to ${e.name}`,description:e.courseCount?`They are also enrolled in the ${n(e.courseCount,`course`)} this cohort is linked to.`:`Search for people by name or email.`}),(0,K.jsxs)(b,{className:`space-y-3`,children:[(0,K.jsx)(Z,{value:d,onChange:f,label:`Search by name or email`,autoFocus:!0}),h.size>0&&(0,K.jsx)(`ul`,{className:`flex flex-wrap gap-1.5`,"aria-label":`Selected people`,children:[...h.values()].map(e=>(0,K.jsxs)(`li`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/10 py-0.5 pr-1 pl-2.5 text-xs font-medium text-primary`,children:[e.name,(0,K.jsx)(`button`,{type:`button`,className:`rounded-full p-0.5 hover:bg-primary/15`,"aria-label":`Unselect ${e.name}`,onClick:()=>w(e,!1),children:(0,K.jsx)(ne,{className:`size-3`})})]},e.id))}),p?_?_.length===0?(0,K.jsxs)(`p`,{className:`py-8 text-center text-sm text-muted-foreground`,children:[`No one matches “`,p,`”.`]}):(0,K.jsx)(`ul`,{className:a(`divide-y overflow-hidden rounded-lg border transition-opacity`,S&&`opacity-70`),children:_.map(e=>(0,K.jsx)(`li`,{children:(0,K.jsxs)(`label`,{className:a(`flex items-center gap-3 px-3 py-2`,e.member?`opacity-60`:`cursor-pointer hover:bg-accent/40`),children:[(0,K.jsx)(oe,{disabled:e.member,checked:e.member||h.has(e.id),onCheckedChange:t=>w(e,t===!0)}),(0,K.jsx)(D,{user:e,size:`xs`}),(0,K.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:e.name}),(0,K.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:e.email})]}),e.member&&(0,K.jsx)(y,{variant:`neutral`,children:`Member`})]})},e.id))}):(0,K.jsx)(`div`,{className:`grid place-items-center py-8`,children:(0,K.jsx)(B,{})}):(0,K.jsx)(`p`,{className:`py-8 text-center text-sm text-muted-foreground`,children:`Start typing a name or email address.`}),_?.length===20&&(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Showing the first 20 matches. Type more to narrow them down.`})]}),(0,K.jsxs)(j,{children:[(0,K.jsx)(c,{type:`button`,variant:`outline`,onClick:()=>o(!1),children:`Cancel`}),(0,K.jsx)(c,{type:`submit`,loading:T.isPending,disabled:h.size===0,children:h.size?`Add ${Y(h.size)}`:`Add people`})]})]})})})}function $({title:e,items:t,hint:n}){return t.length===0?null:(0,K.jsxs)(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 p-3 text-sm`,children:[(0,K.jsxs)(`p`,{className:`font-medium text-amber-800 dark:text-amber-300`,children:[e,` (`,t.length,`)`]}),n&&(0,K.jsx)(`p`,{className:`mt-0.5 text-xs text-amber-800/80 dark:text-amber-300/80`,children:n}),(0,K.jsx)(`ul`,{className:`ck-scrollbar mt-2 max-h-36 space-y-0.5 overflow-y-auto font-mono text-xs break-all`,children:t.map(e=>(0,K.jsx)(`li`,{children:e},e))})]})}function be({cohort:e,open:t,onOpenChange:r,onAdded:i}){let[a,o]=(0,G.useState)(``),[s,d]=(0,G.useState)(null),f=a.split(/[\s,;]+/).filter(Boolean),p=C({mutationFn:()=>u.post(`/admin/cohorts/${e.id}/members`,{emails:f}),onSuccess:async t=>{d(t),ve(t,e.name),await i()},onError:e=>R.error(l(e))}),m=e=>{r(e),e||(d(null),o(``))},h=s?[...s.notFound,...s.invalid]:[];return(0,K.jsx)(x,{open:t,onOpenChange:m,children:(0,K.jsx)(O,{children:s?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(v,{icon:(0,K.jsx)(re,{className:`size-5`}),title:s.added?`Added ${Y(s.added)}`:`No one new was added`,description:s.enrolled?`That made ${n(s.enrolled,`new course enrolment`)} through the cohort's linked courses.`:void 0}),(0,K.jsxs)(b,{className:`space-y-3`,children:[(0,K.jsx)($,{title:`No account found`,items:s.notFound,hint:`Create their accounts under Users, then add them again.`}),(0,K.jsx)($,{title:`Not email addresses`,items:s.invalid}),s.alreadyMembers.length>0&&(0,K.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[Y(s.alreadyMembers.length),` on the list were already in the cohort.`]}),h.length===0&&s.alreadyMembers.length===0&&(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Everyone on the list was added.`})]}),(0,K.jsxs)(j,{children:[(0,K.jsx)(c,{variant:`outline`,onClick:()=>{o(h.join(`
2
+ `)),d(null)},children:h.length?`Fix the rest`:`Add more`}),(0,K.jsx)(c,{onClick:()=>m(!1),children:`Done`})]})]}):(0,K.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),f.length&&f.length<=J&&p.mutate()},children:[(0,K.jsx)(v,{icon:(0,K.jsx)(W,{className:`size-5`}),title:`Add people by email`,description:`Paste email addresses, for example a column from a spreadsheet. Each person needs an account on this site.`}),(0,K.jsx)(b,{children:(0,K.jsx)(M,{label:`Email addresses`,hint:f.length>J?`That's ${f.length} entries. Add up to ${J} at a time.`:`${n(f.length,`entry`,`entries`)}. Separate them with commas, spaces or new lines.`,error:f.length>J?`Add up to ${J} at a time.`:null,children:e=>(0,K.jsx)(N,{...e,rows:8,autoFocus:!0,value:a,onChange:e=>o(e.target.value),placeholder:`ada@school.edu
3
+ grace@school.edu`,className:`font-mono text-[13px]`})})}),(0,K.jsxs)(j,{children:[(0,K.jsx)(c,{type:`button`,variant:`outline`,onClick:()=>m(!1),children:`Cancel`}),(0,K.jsx)(c,{type:`submit`,loading:p.isPending,disabled:f.length===0||f.length>J,children:f.length?`Add ${Y(f.length)}`:`Add people`})]})]})})})}function xe({cohort:t,onChanged:n}){let a=_(),[o,s]=(0,G.useState)(``),[d,f]=(0,G.useState)(1),[p,h]=(0,G.useState)(!1),[g,v]=(0,G.useState)(!1),b=m(o.trim(),300),{data:x,isLoading:S,error:w,refetch:T}=i({queryKey:[`admin`,`cohort`,t.id,`members`,b,d],queryFn:()=>u.get(`/admin/cohorts/${t.id}/members?${X({q:b,page:d,pageSize:q})}`),placeholderData:r}),E=C({mutationFn:e=>u.delete(`/admin/cohorts/${t.id}/members/${e.id}`),onSuccess:async(e,r)=>{await n(),R.success(`Removed ${r.name} from ${t.name}`)},onError:e=>R.error(l(e))}),O=x?Math.max(1,Math.ceil(x.total/q)):1;return(0,K.jsxs)(F,{className:`overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col gap-3 border-b p-4 sm:flex-row sm:items-center`,children:[(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`h3`,{className:`text-[15px] font-semibold tracking-tight`,children:`Members`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:Y(t.memberCount)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(c,{variant:`outline`,size:`sm`,className:`flex-1 sm:flex-none`,onClick:()=>v(!0),children:[(0,K.jsx)(W,{}),` Add by email`]}),(0,K.jsxs)(c,{size:`sm`,className:`flex-1 sm:flex-none`,onClick:()=>h(!0),children:[(0,K.jsx)(P,{}),` Add people`]})]})]}),(t.memberCount>0||b)&&(0,K.jsx)(`div`,{className:`border-b p-3`,children:(0,K.jsx)(Z,{value:o,onChange:e=>{s(e),f(1)},label:`Search members`})}),w?(0,K.jsx)(`div`,{className:`p-4`,children:(0,K.jsx)(V,{error:w,onRetry:()=>T()})}):S||!x?(0,K.jsx)(`div`,{className:`p-4`,children:(0,K.jsx)(z,{className:`h-48`})}):x.items.length===0?(0,K.jsx)(`div`,{className:`p-4`,children:(0,K.jsx)(H,{icon:me,className:`border-none`,title:b?`No members match your search`:`No one in this cohort yet`,description:b?void 0:`Add people one at a time, or paste a list of email addresses.`})}):(0,K.jsx)(`ul`,{className:`divide-y`,"aria-label":`Members of ${t.name}`,children:x.items.map(n=>(0,K.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[(0,K.jsx)(D,{user:n,size:`sm`}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`truncate text-sm font-medium`,children:n.name}),(0,K.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:n.email})]}),n.status===`suspended`&&(0,K.jsx)(y,{variant:`danger`,children:`Suspended`}),(0,K.jsxs)(`span`,{className:`hidden shrink-0 text-xs text-muted-foreground md:block`,children:[`Added `,e(n.addedAt)]}),(0,K.jsx)(c,{variant:`ghost`,size:`icon-sm`,"aria-label":`Remove ${n.name} from the cohort`,onClick:async()=>{await a({title:`Remove ${n.name} from ${t.name}?`,description:t.courseCount?`They stay enrolled in the courses the cohort is linked to.`:`They can be added back at any time.`,confirmLabel:`Remove`,destructive:!0})&&E.mutate(n)},children:(0,K.jsx)(pe,{})})]},n.id))}),x&&O>1&&(0,K.jsx)(`div`,{className:`flex items-center justify-end border-t px-4 py-3 text-sm text-muted-foreground`,children:(0,K.jsx)(Q,{page:d,pages:O,onPage:f})}),(0,K.jsx)(ye,{cohort:t,open:p,onOpenChange:h,onAdded:n}),(0,K.jsx)(be,{cohort:t,open:g,onOpenChange:v,onAdded:n})]})}function Se({cohort:e,open:t,onOpenChange:n,onLinked:o}){let[s,d]=(0,G.useState)(``),f=m(s.trim(),250),[p,h]=(0,G.useState)(``),[g,_]=(0,G.useState)(`student`),{data:S,isFetching:w}=i({queryKey:[`admin`,`courses`,f,1,`cohort-link`],queryFn:()=>u.get(`/admin/courses?${X({q:f,pageSize:8})}`),enabled:t,placeholderData:r}),E=new Set(e.links.map(e=>e.course.id)),D=S?.items.find(e=>e.id===p)??null,k=C({mutationFn:()=>u.post(`/courses/${p}/cohorts`,{cohortId:e.id,role:g}),onSuccess:async e=>{R.success(`Linked to ${e.link.course.title}`,{description:e.enrolled?`Enrolled ${Y(e.enrolled)}.`:`Everyone in the cohort was already enrolled.`}),n(!1),h(``),await o()},onError:e=>R.error(l(e))});return(0,K.jsx)(x,{open:t,onOpenChange:n,children:(0,K.jsx)(O,{children:(0,K.jsxs)(`form`,{className:`flex min-h-0 flex-1 flex-col`,onSubmit:e=>{e.preventDefault(),D&&k.mutate()},children:[(0,K.jsx)(v,{icon:(0,K.jsx)(ce,{className:`size-5`}),title:`Link ${e.name} to a course`,description:fe}),(0,K.jsxs)(b,{className:`space-y-4`,children:[(0,K.jsx)(Z,{value:s,onChange:d,label:`Search courses`,autoFocus:!0}),(0,K.jsx)(`div`,{role:`radiogroup`,"aria-label":`Course`,className:a(`divide-y overflow-hidden rounded-lg border`,w&&`opacity-70`),children:S?S.items.length===0?(0,K.jsx)(`p`,{className:`p-4 text-center text-sm text-muted-foreground`,children:`No courses match your search.`}):S.items.map(e=>{let t=E.has(e.id);return(0,K.jsxs)(`label`,{className:a(`flex items-center gap-3 px-3 py-2.5`,t?`opacity-60`:`cursor-pointer hover:bg-accent/40`,e.id===p&&`bg-primary/[0.06]`),children:[(0,K.jsx)(`input`,{type:`radio`,name:`course`,value:e.id,disabled:t,checked:e.id===p,onChange:()=>h(e.id),className:`size-4 accent-[var(--primary)]`}),(0,K.jsx)(`span`,{className:`size-6 shrink-0 rounded-md`,style:T(e.coverColor),"aria-hidden":!0}),(0,K.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:e.title}),t?(0,K.jsx)(y,{variant:`info`,children:`Linked`}):e.visibility!==`published`&&(0,K.jsx)(y,{variant:`neutral`,className:`capitalize`,children:e.visibility})]},e.id)}):(0,K.jsx)(`div`,{className:`grid place-items-center py-6`,children:(0,K.jsx)(B,{})})}),(0,K.jsx)(M,{label:`Enrol members as`,children:e=>(0,K.jsx)(de,{...e,value:g,onChange:_})})]}),(0,K.jsxs)(j,{children:[(0,K.jsx)(c,{type:`button`,variant:`outline`,onClick:()=>n(!1),children:`Cancel`}),(0,K.jsx)(c,{type:`submit`,loading:k.isPending,disabled:!D,children:D?`Link and enrol ${Y(e.memberCount)}`:`Link to course`})]})]})})})}function Ce({cohort:t,onChanged:n}){let r=_(),[i,a]=(0,G.useState)(!1),o=C({mutationFn:e=>u.delete(`/courses/${e.course.id}/cohorts/${e.id}`),onSuccess:async(e,t)=>{await n(),R.success(`Unlinked from ${t.course.title}. Everyone stays enrolled.`)},onError:e=>R.error(l(e))});return(0,K.jsxs)(F,{children:[(0,K.jsx)(ae,{title:`Linked courses`,description:`Members are enrolled in these courses, including people added later.`}),t.links.length===0?(0,K.jsx)(`p`,{className:`px-5 pb-4 text-sm text-muted-foreground`,children:`Not linked to any course yet.`}):(0,K.jsx)(`ul`,{className:`divide-y border-y`,"aria-label":`Linked courses`,children:t.links.map(t=>(0,K.jsxs)(`li`,{className:`flex items-center gap-3 px-5 py-3`,children:[(0,K.jsx)(`span`,{className:`size-8 shrink-0 rounded-lg`,style:T(t.course.coverColor),"aria-hidden":!0}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(E,{to:`/courses/${t.course.slug}/participants`,className:`block truncate text-sm font-medium hover:text-primary`,children:t.course.title}),(0,K.jsxs)(`p`,{className:`truncate text-xs text-muted-foreground`,children:[`As `,h[t.role].toLowerCase(),`s · linked `,e(t.createdAt)]})]}),(0,K.jsx)(c,{variant:`ghost`,size:`icon-sm`,"aria-label":`Unlink from ${t.course.title}`,onClick:async()=>{await r({title:`Unlink from ${t.course.title}?`,description:`Everyone the cohort enrolled stays enrolled. People added to the cohort later are no longer enrolled in this course.`,confirmLabel:`Unlink`,destructive:!0})&&o.mutate(t)},children:(0,K.jsx)(ue,{})})]},t.id))}),(0,K.jsx)(`div`,{className:`p-3`,children:(0,K.jsxs)(c,{variant:`outline`,className:`w-full`,onClick:()=>a(!0),children:[(0,K.jsx)(ce,{}),` Link to a course`]})}),(0,K.jsx)(Se,{cohort:t,open:i,onOpenChange:a,onLinked:n})]})}function we(){let{cohortId:e}=ee(),t=w(),n=_(),r=he(),[a,o]=(0,G.useState)(!1),{data:s,isLoading:d,error:m,refetch:h}=i({queryKey:[`admin`,`cohort`,e],queryFn:()=>u.get(`/admin/cohorts/${e}`),enabled:!!e});p(s?`${s.name} · Cohorts`:`Cohort`);let g=C({mutationFn:()=>u.delete(`/admin/cohorts/${e}`),onSuccess:async()=>{R.success(`Deleted ${s?.name??`the cohort`}`),t(`/admin/cohorts`),await r()},onError:e=>R.error(l(e))}),v=(0,K.jsxs)(E,{to:`/admin/cohorts`,className:`inline-flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground`,children:[(0,K.jsx)(S,{className:`size-4`}),` All cohorts`]});return m instanceof f&&m.status===404?(0,K.jsxs)(K.Fragment,{children:[v,(0,K.jsx)(H,{className:`mt-4`,icon:I,title:`Cohort not found`,description:`It may have been deleted.`})]}):m?(0,K.jsx)(V,{error:m,onRetry:()=>h()}):d||!s?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(z,{className:`h-10 w-64`}),(0,K.jsx)(z,{className:`h-72`})]}):(0,K.jsxs)(K.Fragment,{children:[v,(0,K.jsxs)(`div`,{className:`mt-3 mb-6 flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold tracking-tight text-balance`,children:s.name}),(0,K.jsx)(`p`,{className:`mt-1 max-w-2xl text-sm text-muted-foreground`,children:s.description||`No description`})]}),(0,K.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,K.jsxs)(c,{variant:`outline`,onClick:()=>o(!0),children:[(0,K.jsx)(L,{}),` Edit`]}),(0,K.jsxs)(c,{variant:`outline`,className:`text-destructive hover:bg-destructive/10`,loading:g.isPending,onClick:async()=>{await n({title:`Delete “${s.name}”?`,description:`The cohort and its course links are removed. Everyone it enrolled stays enrolled in those courses.`,confirmLabel:`Delete cohort`,destructive:!0})&&g.mutate()},children:[(0,K.jsx)(A,{}),` Delete`]})]})]}),(0,K.jsxs)(`div`,{className:`grid items-start gap-5 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,K.jsx)(xe,{cohort:s,onChanged:r}),(0,K.jsx)(Ce,{cohort:s,onChanged:r})]}),a&&(0,K.jsx)(ge,{cohort:s,open:a,onOpenChange:o,onSaved:r})]})}export{we as AdminCohortPage,_e as AdminCohortsPage};
@@ -0,0 +1 @@
1
+ import{Q as e,U as t,dt as n,ft as r,g as i,h as a,m as o,mt as s,r as c,t as l,ut as u,w as d}from"./hooks-EFhyJ5yU.js";import{$ as f,A as p,C as m,D as h,E as g,Gt as _,I as v,It as y,N as b,O as x,Ot as S,at as C,dt as w,k as T,l as E,lt as D,m as O,t as k,u as A}from"./index-CEZdqKdi.js";import{t as j}from"./chevron-left-Bu6IJANV.js";import{t as M}from"./folder-tree-B-DoLXMB.js";import{t as N}from"./library-Bcm33ouq.js";import{t as P}from"./pencil-DFUpj3YP.js";import{t as F}from"./settings-BxdCrDf8.js";import{E as I,c as L,n as R,t as z}from"./misc-CyGhN6HT.js";var B=s(r(),1),V=n(),H={draft:`warning`,published:`success`,archived:`neutral`};function U(){c(`All courses`);let[n,r]=(0,B.useState)(``),[a,s]=(0,B.useState)(1),u=l(n.trim(),300),{data:f,isLoading:p,error:h,refetch:g}=t({queryKey:[`admin`,`courses`,u,a],queryFn:()=>o.get(`/admin/courses?${new URLSearchParams({...u?{q:u}:{},page:String(a),pageSize:`20`})}`),placeholderData:e}),_=f?Math.max(1,Math.ceil(f.total/20)):1;return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`mb-5 flex flex-col gap-3 sm:flex-row sm:items-center`,children:[(0,V.jsxs)(`div`,{className:`relative sm:w-80`,children:[(0,V.jsx)(D,{className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground`}),(0,V.jsx)(A,{value:n,onChange:e=>{r(e.target.value),s(1)},placeholder:`Search courses`,className:`pl-9`,"aria-label":`Search courses`})]}),(0,V.jsx)(i,{asChild:!0,className:`sm:ml-auto`,children:(0,V.jsxs)(y,{to:`/courses/new`,children:[(0,V.jsx)(w,{}),` New course`]})})]}),h?(0,V.jsx)(R,{error:h,onRetry:()=>g()}):p||!f?(0,V.jsx)(L,{className:`h-96`}):f.items.length===0?(0,V.jsx)(z,{icon:N,title:`No courses found`}):(0,V.jsxs)(k,{className:`overflow-hidden`,children:[(0,V.jsx)(`div`,{className:`overflow-x-auto`,children:(0,V.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,V.jsx)(`thead`,{className:`border-b bg-muted/40 text-left text-xs text-muted-foreground`,children:(0,V.jsxs)(`tr`,{children:[(0,V.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Course`}),(0,V.jsx)(`th`,{className:`px-3 py-3 font-medium`,children:`Status`}),(0,V.jsx)(`th`,{className:`hidden px-3 py-3 font-medium md:table-cell`,children:`Teachers`}),(0,V.jsx)(`th`,{className:`hidden px-3 py-3 font-medium sm:table-cell`,children:`Students`}),(0,V.jsx)(`th`,{className:`hidden px-3 py-3 font-medium lg:table-cell`,children:`Created`}),(0,V.jsx)(`th`,{className:`w-12 px-3 py-3`})]})}),(0,V.jsx)(`tbody`,{className:`divide-y`,children:f.items.map(e=>(0,V.jsxs)(`tr`,{className:`hover:bg-accent/30`,children:[(0,V.jsx)(`td`,{className:`px-5 py-3`,children:(0,V.jsxs)(y,{to:`/courses/${e.slug}`,className:`flex items-center gap-3 hover:text-primary`,children:[(0,V.jsx)(`span`,{className:`size-8 shrink-0 rounded-lg`,style:v(e.coverColor)}),(0,V.jsxs)(`span`,{className:`min-w-0`,children:[(0,V.jsx)(`span`,{className:`block truncate font-medium`,children:e.title}),(0,V.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:e.categoryName??`Uncategorised`})]})]})}),(0,V.jsx)(`td`,{className:`px-3 py-3`,children:(0,V.jsx)(m,{variant:H[e.visibility],className:`capitalize`,children:e.visibility})}),(0,V.jsx)(`td`,{className:`hidden px-3 py-3 md:table-cell`,children:(0,V.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(b,{users:e.teachers,max:3}),(0,V.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.teachers.map(e=>e.name).join(`, `)})]})}),(0,V.jsx)(`td`,{className:`hidden px-3 py-3 text-muted-foreground tabular-nums sm:table-cell`,children:e.studentCount}),(0,V.jsx)(`td`,{className:`hidden px-3 py-3 text-muted-foreground lg:table-cell`,children:d(e.createdAt)}),(0,V.jsx)(`td`,{className:`px-3 py-3 text-right`,children:(0,V.jsx)(i,{asChild:!0,variant:`ghost`,size:`icon-sm`,"aria-label":`Settings for ${e.title}`,children:(0,V.jsx)(y,{to:`/courses/${e.slug}/settings`,children:(0,V.jsx)(F,{})})})})]},e.id))})]})}),_>1&&(0,V.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t px-5 py-3 text-sm text-muted-foreground`,children:[(0,V.jsx)(i,{variant:`outline`,size:`icon-sm`,disabled:a<=1,onClick:()=>s(a-1),"aria-label":`Previous page`,children:(0,V.jsx)(j,{})}),(0,V.jsxs)(`span`,{className:`tabular-nums`,children:[a,` / `,_]}),(0,V.jsx)(i,{variant:`outline`,size:`icon-sm`,disabled:a>=_,onClick:()=>s(a+1),"aria-label":`Next page`,children:(0,V.jsx)(S,{})})]})]})]})}function W({category:e,open:t,onOpenChange:n,onDone:r}){let[s,c]=(0,B.useState)(e?.name??``),[l,u]=(0,B.useState)(e?.description??``),d=_({mutationFn:()=>e?o.patch(`/categories/${e.id}`,{name:s,description:l}):o.post(`/categories`,{name:s,description:l}),onSuccess:()=>{I.success(e?`Category updated`:`Category created`),r(),n(!1)},onError:e=>I.error(a(e))});return(0,V.jsx)(g,{open:t,onOpenChange:n,children:(0,V.jsx)(x,{children:(0,V.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),d.mutate()},children:[(0,V.jsx)(p,{icon:(0,V.jsx)(M,{className:`size-5`}),title:e?`Edit category`:`New category`}),(0,V.jsxs)(h,{className:`space-y-4`,children:[(0,V.jsx)(E,{label:`Name`,children:e=>(0,V.jsx)(A,{...e,autoFocus:!0,required:!0,value:s,onChange:e=>c(e.target.value)})}),(0,V.jsx)(E,{label:`Description`,optional:!0,children:e=>(0,V.jsx)(O,{...e,rows:3,value:l,onChange:e=>u(e.target.value)})})]}),(0,V.jsxs)(T,{children:[(0,V.jsx)(i,{type:`button`,variant:`outline`,onClick:()=>n(!1),children:`Cancel`}),(0,V.jsx)(i,{type:`submit`,loading:d.isPending,children:`Save`})]})]})})})}function G(){c(`Categories`);let e=u(),n=f(),[r,s]=(0,B.useState)(null),{data:l,isLoading:d,error:p,refetch:h}=t({queryKey:[`categories`],queryFn:()=>o.get(`/categories`)}),g=()=>e.invalidateQueries({queryKey:[`categories`]}),v=_({mutationFn:e=>o.delete(`/categories/${e}`),onSuccess:async()=>{await g(),I.success(`Category deleted`)},onError:e=>I.error(a(e))});return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`mb-5 flex items-center justify-between gap-3`,children:[(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Categories organise the course catalog.`}),(0,V.jsxs)(i,{onClick:()=>s(`new`),children:[(0,V.jsx)(w,{}),` New category`]})]}),p?(0,V.jsx)(R,{error:p,onRetry:()=>h()}):d||!l?(0,V.jsx)(L,{className:`h-64`}):l.length===0?(0,V.jsx)(z,{icon:M,title:`No categories yet`,description:`Create categories like “Science” or “Languages” to organise the catalog.`}):(0,V.jsx)(k,{className:`divide-y overflow-hidden`,children:l.map(e=>(0,V.jsxs)(`div`,{className:`flex items-center gap-4 px-5 py-4`,children:[(0,V.jsx)(`span`,{className:`grid size-10 place-items-center rounded-xl bg-primary/10 text-primary`,children:(0,V.jsx)(M,{className:`size-4.5`})}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`p`,{className:`font-medium`,children:e.name}),(0,V.jsx)(`p`,{className:`truncate text-sm text-muted-foreground`,children:e.description||`No description`})]}),(0,V.jsxs)(m,{variant:`neutral`,children:[e.courseCount,` published course`,e.courseCount===1?``:`s`]}),(0,V.jsx)(i,{variant:`ghost`,size:`icon-sm`,onClick:()=>s(e),"aria-label":`Edit ${e.name}`,children:(0,V.jsx)(P,{})}),(0,V.jsx)(i,{variant:`ghost`,size:`icon-sm`,"aria-label":`Delete ${e.name}`,onClick:async()=>{await n({title:`Delete “${e.name}”?`,description:`Courses in this category are kept and become uncategorised.`,confirmLabel:`Delete`,destructive:!0})&&v.mutate(e.id)},children:(0,V.jsx)(C,{})})]},e.id))}),r&&(0,V.jsx)(W,{category:r===`new`?void 0:r,open:!!r,onOpenChange:e=>!e&&s(null),onDone:g})]})}export{G as AdminCategoriesPage,U as AdminCoursesPage};
@@ -0,0 +1 @@
1
+ import{C as e,Dt as t,Gt as n,f as r,it as i,l as a,n as o,o as s,t as c,u as l}from"./index-CEZdqKdi.js";import{D as u,H as d,T as f,U as p,V as m,_ as h,dt as g,ft as _,g as v,h as y,m as b,mt as x,r as S,s as C,ut as w}from"./hooks-EFhyJ5yU.js";import{E as T,c as E,n as D,w as O}from"./misc-CyGhN6HT.js";import{t as k}from"./clock-DPBmdKAi.js";import{t as A}from"./inbox-x1U4YU-c.js";import{t as j}from"./mail-x-B6oBqlcw.js";import{t as M}from"./rotate-ccw-yBj9Ri49.js";import{t as N}from"./send-BnVkFV8w.js";import{i as P,n as F,r as I}from"./email-BZ3kGs-R.js";var L={name:`mail-check`,size:24,node:[[`path`,{d:`M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h8`,key:`12jkf8`}],[`path`,{d:`m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7`,key:`1ocrg3`}],[`path`,{d:`m16 19 2 2 4-4`,key:`1b14m6`}]]};L.node;var R=d(L),z=x(_(),1),B=g(),V=[`admin`,`email`];function H(e){return new Intl.DateTimeFormat(void 0,{hour:`numeric`,minute:`2-digit`}).format(new Date(2e3,0,1,e))}function U(e,t){try{return new Intl.DateTimeFormat(void 0,{timeZone:t,weekday:`short`,month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`}).format(new Date(e))}catch{return f(e)}}function W({tone:e,icon:t,title:n,children:r}){return(0,B.jsxs)(`div`,{role:e===`danger`?`alert`:void 0,className:h(`flex gap-3 rounded-xl border px-4 py-3.5 text-sm`,e===`warning`&&`border-amber-500/25 bg-amber-500/8 text-amber-900 dark:text-amber-200`,e===`danger`&&`border-red-500/25 bg-red-500/8 text-red-900 dark:text-red-200`,e===`info`&&`border-sky-500/25 bg-sky-500/8 text-sky-900 dark:text-sky-200`),children:[(0,B.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:t}),(0,B.jsxs)(`div`,{className:`min-w-0 space-y-1`,children:[(0,B.jsx)(`p`,{className:`font-medium`,children:n}),(0,B.jsx)(`div`,{className:`leading-relaxed opacity-90`,children:r})]})]})}function G({children:e}){return(0,B.jsx)(`code`,{className:`rounded bg-foreground/8 px-1 py-0.5 font-mono text-[12px] break-all`,children:e})}function K({label:e,children:t}){return(0,B.jsxs)(`div`,{className:`grid gap-1 py-3 sm:grid-cols-[180px_minmax(0,1fr)] sm:gap-4`,children:[(0,B.jsx)(`dt`,{className:`text-sm text-muted-foreground`,children:e}),(0,B.jsx)(`dd`,{className:`min-w-0 text-sm break-words`,children:t})]})}function q({status:t}){let n=t.enabled?t.transportError?(0,B.jsx)(e,{variant:`danger`,children:`Not working`}):t.transport===`log`?(0,B.jsx)(e,{variant:`info`,children:`Logging only`}):(0,B.jsx)(e,{variant:`success`,children:`On`}):(0,B.jsx)(e,{variant:`neutral`,children:`Off`}),r=t.settings.timezone;return(0,B.jsxs)(c,{children:[(0,B.jsx)(o,{title:`Delivery`,description:`How this server sends email. Set with environment variables or createCoursekit().`,action:n}),(0,B.jsxs)(`dl`,{className:`divide-y px-5 pb-2`,children:[(0,B.jsx)(K,{label:`Transport`,children:t.enabled?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`span`,{className:`font-medium`,children:t.transportName}),t.transportDetail&&(0,B.jsxs)(`span`,{className:`text-muted-foreground`,children:[` · `,t.transportDetail]})]}):(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:`Not configured`})}),(0,B.jsxs)(K,{label:`From`,children:[(0,B.jsx)(`span`,{className:`font-mono text-[13px]`,children:t.from}),t.fromIsDefault&&(0,B.jsx)(e,{variant:`outline`,className:`ml-2`,children:`default`})]}),(0,B.jsx)(K,{label:`Public URL`,children:t.publicUrl??(0,B.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:`Not set: emails go out without links`})}),(0,B.jsx)(K,{label:`Background delivery`,children:t.worker?`Running on this server`:t.enabled?`Off on this server (another process or cron sends email)`:`Off`}),(0,B.jsxs)(K,{label:`Next digests`,children:[`Daily `,U(t.nextDigests.daily,r),` · Weekly `,U(t.nextDigests.weekly,r),(0,B.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:r})]})]})]})}function J({status:e}){let t=[];return e.enabled||t.push((0,B.jsxs)(W,{tone:`info`,icon:(0,B.jsx)(j,{className:`size-4`}),title:`Email is off`,children:[`People only see notifications in the app. To send email, set `,(0,B.jsx)(G,{children:`COURSEKIT_SMTP_URL`}),` (for example`,` `,(0,B.jsx)(G,{children:`smtp://user:password@smtp.example.com:587`}),`) and `,(0,B.jsx)(G,{children:`COURSEKIT_MAIL_FROM`}),`, install `,(0,B.jsx)(G,{children:`nodemailer`}),` and restart. To try it out locally, `,(0,B.jsx)(G,{children:`COURSEKIT_MAIL_TRANSPORT=log`}),` prints emails and saves them in the data folder. Everyone's preferences are kept in the meantime.`]},`off`)),e.transportError&&t.push((0,B.jsx)(W,{tone:`danger`,icon:(0,B.jsx)(O,{className:`size-4`}),title:`Email can't be sent`,children:e.transportError},`error`)),e.enabled&&!e.publicUrl&&t.push((0,B.jsxs)(W,{tone:`warning`,icon:(0,B.jsx)(i,{className:`size-4`}),title:`Emails have no links`,children:[`Without the site's public address, emails can't link to it or include unsubscribe links. Set`,` `,(0,B.jsx)(G,{children:`COURSEKIT_PUBLIC_URL`}),` (for example `,(0,B.jsx)(G,{children:`https://learn.example.com`}),`) and restart.`]},`url`)),e.transport===`smtp`&&e.fromIsDefault&&t.push((0,B.jsxs)(W,{tone:`warning`,icon:(0,B.jsx)(i,{className:`size-4`}),title:`No from address set`,children:[`Mail servers often reject messages from addresses they don't know. Set `,(0,B.jsx)(G,{children:`COURSEKIT_MAIL_FROM`}),` to an address your server may send from.`]},`from`)),t.length?(0,B.jsx)(`div`,{className:`space-y-3`,children:t}):null}function Y({status:e}){let t=w(),r=n({mutationFn:()=>b.post(`/admin/email/retry-failed`),onSuccess:async({requeued:e})=>{T.success(e===1?`1 email will be retried`:`${e} emails will be retried`),await t.invalidateQueries({queryKey:V})},onError:e=>T.error(y(e))}),{outbox:i,lastError:a}=e;return(0,B.jsxs)(`section`,{"aria-labelledby":`outbox-title`,className:`space-y-3`,children:[(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,B.jsx)(`h2`,{id:`outbox-title`,className:`text-[15px] font-semibold tracking-tight`,children:`Outbox`}),(0,B.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[e.lastSentAt?`Last sent ${u(e.lastSentAt)}`:`Nothing sent yet`,` · kept for 30 days`]})]}),(0,B.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-4`,children:[(0,B.jsx)(s,{icon:A,label:`Queued`,value:i.pending,tone:`sky`,hint:`Waiting or retrying`}),(0,B.jsx)(s,{icon:N,label:`Sending`,value:i.sending,tone:`violet`}),(0,B.jsx)(s,{icon:R,label:`Sent`,value:i.sent,tone:`emerald`}),(0,B.jsx)(s,{icon:j,label:`Failed`,value:i.failed,tone:`rose`,hint:`Gave up after retries`})]}),(a||i.failed>0)&&(0,B.jsxs)(c,{className:`flex flex-col gap-3 p-4 sm:flex-row sm:items-start sm:justify-between`,children:[(0,B.jsx)(`div`,{className:`min-w-0 text-sm`,children:a?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`p`,{className:`font-medium`,children:[`Last error `,u(a.at)]}),(0,B.jsx)(`p`,{className:`mt-0.5 break-words text-muted-foreground`,children:a.message}),(0,B.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[`To `,a.to,` ·`,` `,a.status===`sent`?`delivered on a later try`:a.status===`failed`?`gave up`:`will be retried`]})]}):(0,B.jsx)(`p`,{className:`text-muted-foreground`,children:`Some emails could not be delivered.`})}),i.failed>0&&(0,B.jsxs)(v,{variant:`outline`,size:`sm`,onClick:()=>r.mutate(),loading:r.isPending,className:`shrink-0`,children:[(0,B.jsx)(M,{}),` Retry failed`]})]})]})}function X({status:e}){let t=w(),[i,s]=(0,z.useState)(e.settings),l=e.settings,u=JSON.stringify(i)!==JSON.stringify(l),d=(0,z.useMemo)(()=>{let e=typeof Intl.supportedValuesOf==`function`?Intl.supportedValuesOf(`timeZone`):[];return e.includes(i.timezone)?e:[i.timezone,...e]},[i.timezone]),f=n({mutationFn:()=>b.put(`/admin/email/settings`,i),onSuccess:e=>{t.setQueryData(V,e),s(e.settings),T.success(`Email settings saved`)},onError:e=>T.error(y(e))});return(0,B.jsxs)(c,{children:[(0,B.jsx)(o,{title:`Defaults and digests`,description:`People can change their own delivery on their profile page.`}),(0,B.jsxs)(`form`,{className:`grid gap-4 px-5 pb-5 sm:grid-cols-2`,onSubmit:e=>{e.preventDefault(),f.mutate()},children:[(0,B.jsx)(a,{label:`Default delivery`,hint:`For new people and anyone who hasn't chosen.`,className:`sm:col-span-2`,children:e=>(0,B.jsx)(r,{...e,value:i.defaultFrequency,onChange:e=>s({...i,defaultFrequency:e.target.value}),children:F.map(e=>(0,B.jsx)(`option`,{value:e,children:I[e]},e))})}),(0,B.jsx)(a,{label:`Digest time`,children:e=>(0,B.jsx)(r,{...e,value:i.digestHour,onChange:e=>s({...i,digestHour:Number(e.target.value)}),children:Array.from({length:24},(e,t)=>(0,B.jsx)(`option`,{value:t,children:H(t)},t))})}),(0,B.jsx)(a,{label:`Weekly digest day`,children:e=>(0,B.jsx)(r,{...e,value:i.digestWeekday,onChange:e=>s({...i,digestWeekday:Number(e.target.value)}),children:P.map((e,t)=>(0,B.jsx)(`option`,{value:t,children:e},e))})}),(0,B.jsx)(a,{label:`Time zone`,hint:`Digest times follow this time zone.`,className:`sm:col-span-2`,children:e=>(0,B.jsx)(r,{...e,value:i.timezone,onChange:e=>s({...i,timezone:e.target.value}),children:d.map(e=>(0,B.jsx)(`option`,{value:e,children:e.replace(/_/g,` `)},e))})}),(0,B.jsxs)(`div`,{className:`flex justify-end gap-2 sm:col-span-2`,children:[u&&(0,B.jsx)(v,{type:`button`,variant:`ghost`,onClick:()=>s(l),children:`Reset`}),(0,B.jsx)(v,{type:`submit`,loading:f.isPending,disabled:!u,children:`Save settings`})]})]})]})}function Z({status:e}){let r=C(),i=w(),[s,u]=(0,z.useState)(r?.email??``),[d,f]=(0,z.useState)(null),h=n({mutationFn:()=>b.post(`/admin/email/test`,{to:s.trim()}),onSuccess:({id:e})=>f(e),onError:e=>T.error(y(e))}),g=p({queryKey:[`admin`,`email`,`message`,d],queryFn:()=>b.get(`/admin/email/messages/${d}`),enabled:!!d,refetchInterval:e=>e.state.data&&(e.state.data.status===`sent`||e.state.data.status===`failed`)?!1:1500}),_=g.data?.status;(0,z.useEffect)(()=>{_===`sent`&&T.success(`Test email sent`),_===`failed`&&T.error(`The test email could not be sent`),(_===`sent`||_===`failed`)&&i.invalidateQueries({queryKey:V})},[_,i]);let x=!!d&&_!==`sent`&&_!==`failed`,[S,E]=(0,z.useState)(!1);return(0,z.useEffect)(()=>{if(E(!1),!x)return;let e=setTimeout(()=>E(!0),2e4);return()=>clearTimeout(e)},[x,d]),(0,B.jsxs)(c,{children:[(0,B.jsx)(o,{title:`Send a test email`,description:`Checks the whole path: the outbox, the transport and your inbox.`}),(0,B.jsxs)(`form`,{className:`space-y-3 px-5 pb-5`,onSubmit:e=>{e.preventDefault(),f(null),h.mutate()},children:[(0,B.jsx)(a,{label:`Send to`,children:t=>(0,B.jsx)(l,{...t,type:`email`,required:!0,autoComplete:`email`,value:s,onChange:e=>u(e.target.value),disabled:!e.enabled})}),(0,B.jsxs)(v,{type:`submit`,variant:`outline`,className:`w-full`,loading:h.isPending,disabled:!e.enabled||x||!s.trim(),children:[(0,B.jsx)(N,{}),` Send test email`]}),!e.enabled&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Set up a transport to send a test email.`}),d&&(0,B.jsx)(`p`,{role:`status`,"aria-live":`polite`,className:`flex items-start gap-2 text-sm`,children:_===`sent`?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(t,{className:`mt-0.5 size-4 shrink-0 text-emerald-600 dark:text-emerald-400`}),(0,B.jsxs)(`span`,{children:[`Sent to `,g.data.to,`.`,` `,e.transport===`log`?`It is in the emails folder and the server log.`:`Check the inbox (and the spam folder).`]})]}):_===`failed`?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(O,{className:`mt-0.5 size-4 shrink-0 text-destructive`}),(0,B.jsx)(`span`,{className:`min-w-0 break-words`,children:g.data.lastError??`Sending failed.`})]}):e.worker&&!S?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(m,{className:`mt-0.5 size-4 shrink-0 animate-spin text-muted-foreground`}),(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:`Sending…`})]}):e.worker?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(k,{className:`mt-0.5 size-4 shrink-0 text-muted-foreground`}),(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:`Still queued. Check the delivery status at the top of this page.`})]}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(k,{className:`mt-0.5 size-4 shrink-0 text-muted-foreground`}),(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:`Queued. Background delivery is off here, so it goes out with the next delivery run.`})]})})]})]})}function Q(){S(`Email`);let{data:e,isLoading:t,error:n,refetch:r}=p({queryKey:V,queryFn:()=>b.get(`/admin/email`),refetchInterval:15e3});return n?(0,B.jsx)(D,{error:n,onRetry:()=>r()}):t||!e?(0,B.jsxs)(`div`,{className:`space-y-6`,children:[(0,B.jsx)(E,{className:`h-64`}),(0,B.jsx)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-4`,children:[0,1,2,3].map(e=>(0,B.jsx)(E,{className:`h-24`},e))}),(0,B.jsx)(E,{className:`h-72`})]}):(0,B.jsxs)(`div`,{className:`space-y-6`,children:[(0,B.jsx)(J,{status:e}),(0,B.jsx)(q,{status:e}),(0,B.jsx)(Y,{status:e}),(0,B.jsxs)(`div`,{className:`grid items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,B.jsx)(X,{status:e},JSON.stringify(e.settings)),(0,B.jsx)(Z,{status:e})]})]})}export{Q as default};
@@ -0,0 +1 @@
1
+ import{t as e}from"./contact-NCWQa7wc.js";import{t}from"./folder-tree-B-DoLXMB.js";import{Bt as n,Lt as r,_ as i,a,gt as o,tt as s,yt as c,zt as l}from"./index-CEZdqKdi.js";import{t as u}from"./library-Bcm33ouq.js";import{t as d}from"./mail-CQ9yiBph.js";import{t as f}from"./settings-BxdCrDf8.js";import{_ as p,dt as m,s as h}from"./hooks-EFhyJ5yU.js";var g=m(),_=[{to:`/admin`,label:`Overview`,icon:c,end:!0},{to:`/admin/users`,label:`Users`,icon:s},{to:`/admin/cohorts`,label:`Cohorts`,icon:e},{to:`/admin/courses`,label:`Courses`,icon:u},{to:`/admin/categories`,label:`Categories`,icon:t},{to:`/admin/settings`,label:`Site settings`,icon:f},{to:`/admin/email`,label:`Email`,icon:d},{to:`/admin/badges`,label:`Badges`,icon:o}];function v(){return h()?.role===`admin`?(0,g.jsxs)(i,{children:[(0,g.jsx)(a,{title:`Administration`,description:`Manage people, courses and how your site looks.`}),(0,g.jsx)(`nav`,{className:`ck-no-scrollbar mb-7 flex gap-1 overflow-x-auto border-b`,children:_.map(e=>(0,g.jsxs)(r,{to:e.to,end:e.end,className:({isActive:e})=>p(`relative -mb-px flex h-10 shrink-0 items-center gap-2 border-b-2 border-transparent px-3 text-sm font-medium text-muted-foreground transition-colors hover:text-foreground`,e&&`border-primary text-foreground`),children:[(0,g.jsx)(e.icon,{className:`size-4`}),e.label]},e.to))}),(0,g.jsx)(n,{})]}):(0,g.jsx)(l,{to:`/`,replace:!0})}export{v as default};