Skip to content

Commit

Permalink
Merge pull request #2 from qin-guan/feat-delete-survey
Browse files Browse the repository at this point in the history
  • Loading branch information
qin-guan authored Jul 17, 2023
2 parents 76e18a4 + c349607 commit 633dbbb
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pages/dashboard/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ useSeoMeta({
const toast = useToast()
const { $client } = useNuxtApp()
const { data: surveys, pending: surveysPending, error: surveysError } = await $client.survey.list.useQuery(undefined, { lazy: true })
const { data: surveys, pending: surveysPending, error: surveysError, refresh: surveyRefresh } = await $client.survey.list.useQuery(undefined, { lazy: true })
const { data: pastWinners, pending: pastWinnersPending, error: pastWinnersError, refresh: pastWinnersRefresh } = await $client.luckyDraw.pastWinners.useQuery(undefined, { lazy: true })

Check warning on line 21 in pages/dashboard/index.vue

View workflow job for this annotation

GitHub Actions / ci

'pastWinnersPending' is assigned a value but never used. Allowed unused vars must match /^_/u

Check warning on line 21 in pages/dashboard/index.vue

View workflow job for this annotation

GitHub Actions / ci

'pastWinnersError' is assigned a value but never used. Allowed unused vars must match /^_/u
const visible = ref(false)
Expand Down Expand Up @@ -80,6 +80,24 @@ async function deleteWinner(id: string) {
}
}
}
async function deleteSurvey(id: string) {
try {
await $client.survey.delete.mutate({
id,
})
await surveyRefresh()
}
catch (err) {
console.error(err)
if (err instanceof TRPCClientError) {
toast.add({
severity: 'error',
summary: err.message,
})
}
}
}
</script>

<template>
Expand Down Expand Up @@ -142,6 +160,7 @@ async function deleteWinner(id: string) {
<NuxtLink :to="`/dashboard/surveys/${slotProps.data.id}`">
<Button label="Edit" size="small" link />
</NuxtLink>
<Button label="Delete" size="small" link @click="deleteSurvey(slotProps.data.id)"/>

Check warning on line 163 in pages/dashboard/index.vue

View workflow job for this annotation

GitHub Actions / ci

Expected a space before '/>', but not found
</template>
</Column>
</DataTable>
Expand Down

0 comments on commit 633dbbb

Please sign in to comment.