Skip to content

Commit a832b2f

Browse files
feat(project): project settings advanced (#91)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
1 parent dfd3a5e commit a832b2f

File tree

2 files changed

+172
-4
lines changed

2 files changed

+172
-4
lines changed
Lines changed: 169 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,173 @@
11
<template>
22
<div class="space-y-6">
3-
<UCard padded />
3+
<UCard>
4+
<h2 class="text-lg font-medium leading-6 u-text-gray-900">
5+
Transfer project
6+
</h2>
7+
<p class="mt-1 text-sm u-text-gray-400">
8+
Your project and all of its dependencies will be transferred without downtime or workflow interruptions to the selected destination.
9+
</p>
10+
<div class="flex flex-col justify-between gap-4 mt-5 sm:flex-row">
11+
<USelect
12+
v-model="transferForm.destination"
13+
size="sm"
14+
icon="heroicons-outline:switch-horizontal"
15+
placeholder="Select a destination"
16+
:options="transferOptions"
17+
name="destination"
18+
/>
19+
<div class="flex justify-end">
20+
<UButton label="Transfer project" size="sm" :disabled="!transferForm.destination" @click="onTransfer()" />
21+
</div>
22+
</div>
23+
</UCard>
24+
<UCard>
25+
<h2 class="text-lg font-medium leading-6 u-text-gray-900">
26+
Delete project
27+
</h2>
28+
<p class="mt-1 text-sm u-text-gray-400">
29+
Your project and all of its dependencies will be transferred without downtime or workflow interruptions to the selected destination.
30+
</p>
31+
<div class="flex justify-end mt-5">
32+
<UButton variant="red" label="Delete project" size="sm" @click="onDelete()" />
33+
</div>
34+
</UCard>
35+
36+
<UAlertDialog
37+
v-model="transferModal"
38+
icon="heroicons-outline:switch-horizontal"
39+
icon-class="text-gray-600"
40+
icon-wrapper-class="w-12 h-12 bg-gray-200 sm:h-10 sm:w-10"
41+
title="Transfer project"
42+
description="Are you sure you want to transfer this project?"
43+
@confirm="confirmTransfer()"
44+
/>
45+
<UAlertDialog
46+
v-model="deleteModal"
47+
icon="heroicons-outline:x"
48+
icon-class="text-red-600"
49+
icon-wrapper-class="w-12 h-12 bg-red-100 sm:h-10 sm:w-10"
50+
title="Delete project"
51+
description="Are you sure you want to delete this project? This action is not reversible. Please be certain."
52+
@confirm="confirmDelete()"
53+
/>
454
</div>
555
</template>
56+
57+
<script setup lang="ts">
58+
import type { Ref, PropType } from 'vue'
59+
import { User, Project, Team } from '~/types'
60+
61+
const props = defineProps({
62+
team: {
63+
type: Object as PropType<Team>,
64+
default: null
65+
},
66+
project: {
67+
type: Object as PropType<Project>,
68+
required: true
69+
}
70+
})
71+
72+
const client = useStrapiClient()
73+
const { delete: _delete } = useStrapi4()
74+
const user = useStrapiUser() as Ref<User>
75+
const route = useRoute()
76+
const router = useRouter()
77+
const { $toast } = useNuxtApp()
78+
79+
const transferForm = reactive({ destination: null })
80+
const transferModal = ref(false)
81+
const deleteModal = ref(false)
82+
const transferring = ref(false)
83+
const deleting = ref(false)
84+
85+
const teams = computed(() => {
86+
return user.value.memberships
87+
.filter(membership => props.team?.id !== membership.team.id)
88+
.map(membership => ({
89+
text: membership.team.name,
90+
value: membership.team.id,
91+
slug: membership.team.slug
92+
}))
93+
})
94+
95+
const transferOptions = computed(() => {
96+
const options = []
97+
98+
if (props.team) {
99+
options.push({
100+
text: 'Personal account',
101+
children: [
102+
{
103+
text: user.value.username,
104+
value: user.value.username
105+
}
106+
]
107+
})
108+
}
109+
110+
if (teams.value.length) {
111+
options.push({
112+
text: 'Teams',
113+
children: teams.value
114+
})
115+
}
116+
117+
return options
118+
})
119+
120+
const onTransfer = () => {
121+
transferModal.value = true
122+
}
123+
124+
const confirmTransfer = async () => {
125+
transferring.value = true
126+
127+
try {
128+
await client(`/projects/${props.project.id}/transfer`, {
129+
method: 'POST',
130+
body: {
131+
destination: transferForm.destination
132+
}
133+
})
134+
135+
const team = transferForm.destination === user.value.username
136+
? user.value.username
137+
// eslint-disable-next-line eqeqeq
138+
: teams.value.filter(team => transferForm.destination == team.value)[0].slug
139+
140+
router.replace({ name: '@team-projects', params: { team } })
141+
142+
$toast.success({
143+
title: 'Success',
144+
description: 'Your project has been transferred!'
145+
})
146+
} catch (e) {}
147+
148+
transferring.value = false
149+
}
150+
151+
const onDelete = () => {
152+
deleteModal.value = true
153+
}
154+
155+
const confirmDelete = async () => {
156+
deleting.value = true
157+
158+
try {
159+
await _delete<Project>('projects', props.project.id)
160+
161+
const team = props.team ? props.team.slug : user.value.username
162+
163+
router.push({ name: '@team-projects', params: { team } })
164+
165+
$toast.success({
166+
title: 'Success',
167+
description: 'Your project has been deleted!'
168+
})
169+
} catch (e) {}
170+
171+
deleting.value = false
172+
}
173+
</script>

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,9 @@
567567
vite "^2.8.5"
568568

569569
"@nuxthq/ui@npm:@nuxthq/ui-edge@latest":
570-
version "0.0.2-27435560.7737242"
571-
resolved "https://registry.yarnpkg.com/@nuxthq/ui-edge/-/ui-edge-0.0.2-27435560.7737242.tgz#e3cd3f198f7073c7b955f4dec5350e04751219c6"
572-
integrity sha512-nG2CYFpXmtw68hRfNt2mroRQOvZ5dlwjxCcjQsNESHPlsbodXV6M/DR3HKsMuIl/5gT+QkORAGx7lItM+G4KWQ==
570+
version "0.0.2-27435844.4d0709a"
571+
resolved "https://registry.yarnpkg.com/@nuxthq/ui-edge/-/ui-edge-0.0.2-27435844.4d0709a.tgz#6f481cf6394b20c63a947dd646af74a31d043cbe"
572+
integrity sha512-Zyf6KAW1B5yCYU4DTBpmZsdVb6tendBJMLntMX6kphDrClIhBStd1RNgTyxU0NMi1NT4PXgZFjPQvBi48HhZuQ==
573573
dependencies:
574574
"@headlessui/vue" "1.4.3"
575575
"@iconify/vue" "^3.1.3"

0 commit comments

Comments
 (0)