|
| 1 | +<script lang="ts"> |
| 2 | + import { graphql } from '$houdini'; |
| 3 | + import * as m from '$lib/paraglide/messages'; |
| 4 | + import Modal from './Modal.svelte'; |
| 5 | + import Section from './Section.svelte'; |
| 6 | + import type { ModalData } from './types'; |
| 7 | +
|
| 8 | + let { data } = $props(); |
| 9 | +
|
| 10 | + let modalData = $state<ModalData>(); |
| 11 | +
|
| 12 | + const cleanupDelegationMembers = graphql(` |
| 13 | + mutation CleanupDelegationMembers($conferenceId: ID!) { |
| 14 | + deleteDeadDelegationMembers(conferenceId: $conferenceId) { |
| 15 | + id |
| 16 | + user { |
| 17 | + given_name |
| 18 | + family_name |
| 19 | + } |
| 20 | + } |
| 21 | + } |
| 22 | + `); |
| 23 | +
|
| 24 | + const cleanupIndividualParticipants = graphql(` |
| 25 | + mutation CleanupIndividualParticipants($conferenceId: ID!) { |
| 26 | + deleteDeadSingleParticipants(conferenceId: $conferenceId) { |
| 27 | + id |
| 28 | + user { |
| 29 | + given_name |
| 30 | + family_name |
| 31 | + } |
| 32 | + } |
| 33 | + } |
| 34 | + `); |
| 35 | +
|
| 36 | + const cleanupDelegations = graphql(` |
| 37 | + mutation CleanupDelegations($conferenceId: ID!) { |
| 38 | + deleteEmptyDelegations(conferenceId: $conferenceId) { |
| 39 | + id |
| 40 | + } |
| 41 | + } |
| 42 | + `); |
| 43 | +
|
| 44 | + const cleanupSupervisors = graphql(` |
| 45 | + mutation CleanupSupervisors($conferenceId: ID!) { |
| 46 | + deleteDeadSupervisors(conferenceId: $conferenceId) { |
| 47 | + id |
| 48 | + user { |
| 49 | + given_name |
| 50 | + family_name |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + `); |
| 55 | +
|
| 56 | + function createModalData( |
| 57 | + message: string, |
| 58 | + result: { user?: { given_name: string; family_name: string }; id?: string }[] | undefined |
| 59 | + ) { |
| 60 | + if (!result) return { message: 'Error - No result', count: 0, detailArray: [] }; |
| 61 | + return { |
| 62 | + message, |
| 63 | + count: result.length, |
| 64 | + detailArray: |
| 65 | + result |
| 66 | + .map((item) => (item.user ? `${item.user.given_name} ${item.user.family_name}` : item.id)) |
| 67 | + .filter((item) => item !== undefined) ?? [] |
| 68 | + }; |
| 69 | + } |
| 70 | +</script> |
| 71 | + |
| 72 | +<div class="flex w-full flex-col flex-wrap gap-8 p-10"> |
| 73 | + <div class="flex flex-col gap-2"> |
| 74 | + <h2 class="text-2xl font-bold">{m.cleanup()}</h2> |
| 75 | + <p>{@html m.cleanupDescription()}</p> |
| 76 | + </div> |
| 77 | + <Section |
| 78 | + title={m.cleanupDelegationMembers()} |
| 79 | + description={m.cleanupDelegationMembersDescription()} |
| 80 | + btnText={m.cleanupDelegationMembersButton()} |
| 81 | + action={async () => { |
| 82 | + modalData = createModalData( |
| 83 | + m.cleanupDelegationMembersSuccess(), |
| 84 | + (await cleanupDelegationMembers.mutate({ conferenceId: data.conferenceId }))?.data |
| 85 | + ?.deleteDeadDelegationMembers |
| 86 | + ); |
| 87 | + }} |
| 88 | + /> |
| 89 | + <Section |
| 90 | + title={m.cleanupIndividualParticipants()} |
| 91 | + description={m.cleanupIndividualParticipantsDescription()} |
| 92 | + btnText={m.cleanupIndividualParticipantsButton()} |
| 93 | + action={async () => { |
| 94 | + modalData = createModalData( |
| 95 | + m.cleanupIndividualParticipantsSuccess(), |
| 96 | + (await cleanupIndividualParticipants.mutate({ conferenceId: data.conferenceId }))?.data |
| 97 | + ?.deleteDeadSingleParticipants |
| 98 | + ); |
| 99 | + }} |
| 100 | + /> |
| 101 | + <Section |
| 102 | + title={m.cleanupDelegations()} |
| 103 | + description={m.cleanupDelegationsDescription()} |
| 104 | + btnText={m.cleanupDelegationsButton()} |
| 105 | + action={async () => { |
| 106 | + modalData = createModalData( |
| 107 | + m.cleanupDelegationsSuccess(), |
| 108 | + (await cleanupDelegations.mutate({ conferenceId: data.conferenceId }))?.data |
| 109 | + ?.deleteEmptyDelegations |
| 110 | + ); |
| 111 | + }} |
| 112 | + /> |
| 113 | + <Section |
| 114 | + title={m.cleanupSupervisors()} |
| 115 | + description={m.cleanupSupervisorsDescription()} |
| 116 | + btnText={m.cleanupSupervisorsButton()} |
| 117 | + action={async () => { |
| 118 | + modalData = createModalData( |
| 119 | + m.cleanupSupervisorsSuccess(), |
| 120 | + (await cleanupSupervisors.mutate({ conferenceId: data.conferenceId }))?.data |
| 121 | + ?.deleteDeadSupervisors |
| 122 | + ); |
| 123 | + }} |
| 124 | + /> |
| 125 | +</div> |
| 126 | + |
| 127 | +<Modal {modalData} open={!!modalData} closeModal={() => (modalData = undefined)} /> |
0 commit comments