Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.

Migrate ModalCreation component to Composition API #1625

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
248 changes: 121 additions & 127 deletions components/ui/ModalCreation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,143 +72,137 @@
</Modal>
</template>

<script>
<script setup>
import { Multiselect } from 'vue-multiselect'
import CrossIcon from '~/assets/images/utils/x.svg'
import CheckIcon from '~/assets/images/utils/right-arrow.svg'
import Modal from '~/components/ui/Modal.vue'

export default {
components: {
CrossIcon,
CheckIcon,
Modal,
Multiselect,
},
props: {
organizationId: {
type: String,
required: false,
default: null,
},
},
setup() {
const tags = useTags()
const data = useNuxtApp()
const router = useRouter()
const tags = useTags()

Check failure on line 83 in components/ui/ModalCreation.vue

View workflow job for this annotation

GitHub Actions / build

'tags' is assigned a value but never used

const modal = ref(null)

return { tags }
const name = ref('')
const slug = ref('')
const description = ref('')
const manualSlug = ref(false)
const visibilities = ref([
{
actual: 'approved',
display: 'Public',
},
data() {
return {
name: '',
slug: '',
description: '',
manualSlug: false,
visibilities: [
{
actual: 'approved',
display: 'Public',
},
{
actual: 'private',
display: 'Private',
},
{
actual: 'unlisted',
display: 'Unlisted',
},
],
visibility: {
actual: 'approved',
display: 'Public',
},
}
{
actual: 'private',
display: 'Private',
},
{
actual: 'unlisted',
display: 'Unlisted',
},
methods: {
cancel() {
this.$refs.modal.hide()
},
async createProject() {
startLoading()

const formData = new FormData()

const auth = await useAuth()

const projectData = {
title: this.name.trim(),
project_type: 'mod',
slug: this.slug,
description: this.description.trim(),
body: '',
requested_status: this.visibility.actual,
initial_versions: [],
team_members: [
{
user_id: auth.value.user.id,
name: auth.value.user.username,
role: 'Owner',
},
],
categories: [],
client_side: 'required',
server_side: 'required',
license_id: 'LicenseRef-Unknown',
is_draft: true,
}

if (this.organizationId) {
projectData.organization_id = this.organizationId
}

formData.append('data', JSON.stringify(projectData))

try {
await useBaseFetch('project', {
method: 'POST',
body: formData,
headers: {
'Content-Disposition': formData,
},
})

this.$refs.modal.hide()
await this.$router.push({
name: 'type-id',
params: {
type: 'project',
id: this.slug,
},
})
} catch (err) {
this.$notify({
group: 'main',
title: 'An error occurred',
text: err.data.description,
type: 'error',
})
}
stopLoading()
},
show() {
this.projectType = this.tags.projectTypes[0].display
this.name = ''
this.slug = ''
this.description = ''
this.manualSlug = false
this.$refs.modal.show()
},
updatedName() {
if (!this.manualSlug) {
this.slug = this.name
.trim()
.toLowerCase()
.replaceAll(' ', '-')
.replaceAll(/[^a-zA-Z0-9!@$()`.+,_"-]/g, '')
.replaceAll(/--+/gm, '-')
}
},
])
const visibility = ref({
actual: 'approved',
display: 'Public',
})

const props = defineProps({
organizationId: {
type: String,
required: false,
default: null,
},
})

function cancel() {
modal.value.hide()
}
async function createProject() {
startLoading()

const formData = new FormData()

const auth = await useAuth()

const projectData = {
title: name.value.trim(),
project_type: 'mod',
slug: slug.value,
description: description.value.trim(),
body: '',
requested_status: visibility.value.actual,
initial_versions: [],
team_members: [
{
user_id: auth.value.user.id,
name: auth.value.user.username,
role: 'Owner',
},
],
categories: [],
client_side: 'required',
server_side: 'required',
license_id: 'LicenseRef-Unknown',
is_draft: true,
}

if (props.organizationId) {
projectData.organization_id = props.organizationId
}

formData.append('data', JSON.stringify(projectData))

try {
await useBaseFetch('project', {
method: 'POST',
body: formData,
headers: {
'Content-Disposition': formData,
},
})

modal.value.hide()
await router.push({
name: 'type-id',
params: {
type: 'project',
id: slug.value,
},
})
} catch (err) {
data.$notify({
group: 'main',
title: 'An error occurred',
text: err.data.description,
type: 'error',
})
}
stopLoading()
}

function show() {
name.value = ''
slug.value = ''
description.value = ''
manualSlug.value = false
modal.value.show()
}

function updatedName() {
if (!manualSlug.value) {
slug.value = name.value
.trim()
.toLowerCase()
.replaceAll(' ', '-')
.replaceAll(/[^a-zA-Z0-9!@$()`.+,_"-]/g, '')
.replaceAll(/--+/gm, '-')
}
}

defineExpose({
show,
})
</script>

<style scoped lang="scss">
Expand Down
Loading