feat: delete zoom accounts from settings
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
:options="{
|
||||
title:
|
||||
accountID === 'new' ? __('New Zoom Account') : __('Edit Zoom Account'),
|
||||
size: 'lg',
|
||||
size: 'xl',
|
||||
actions: [
|
||||
{
|
||||
label: __('Save'),
|
||||
@@ -17,17 +17,17 @@
|
||||
}"
|
||||
>
|
||||
<template #body-content>
|
||||
<div class="grid grid-cols-2 gap-5">
|
||||
<Link
|
||||
v-model="account.member"
|
||||
:label="__('Member')"
|
||||
doctype="User"
|
||||
:onCreate="(value, close) => openSettings('Members', close)"
|
||||
:required="true"
|
||||
/>
|
||||
<div class="mb-4">
|
||||
<FormControl
|
||||
v-model="account.account_id"
|
||||
:label="__('Account ID')"
|
||||
v-model="account.enabled"
|
||||
:label="__('Enabled')"
|
||||
type="checkbox"
|
||||
/>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-5">
|
||||
<FormControl
|
||||
v-model="account.name"
|
||||
:label="__('Account Name')"
|
||||
type="text"
|
||||
:required="true"
|
||||
/>
|
||||
@@ -37,25 +37,40 @@
|
||||
type="text"
|
||||
:required="true"
|
||||
/>
|
||||
<Link
|
||||
v-model="account.member"
|
||||
:label="__('Member')"
|
||||
doctype="Course Evaluator"
|
||||
:onCreate="(value, close) => openSettings('Members', close)"
|
||||
:required="true"
|
||||
/>
|
||||
<FormControl
|
||||
v-model="account.client_secret"
|
||||
:label="__('Client Secret')"
|
||||
type="password"
|
||||
:required="true"
|
||||
/>
|
||||
<FormControl
|
||||
v-model="account.account_id"
|
||||
:label="__('Account ID')"
|
||||
type="text"
|
||||
:required="true"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { Dialog, FormControl } from 'frappe-ui'
|
||||
import { call, Dialog, FormControl, toast } from 'frappe-ui'
|
||||
import { inject, reactive, watch } from 'vue'
|
||||
import { User } from '@/components/Settings/types'
|
||||
import { openSettings } from '@/utils'
|
||||
import { openSettings, cleanError } from '@/utils'
|
||||
import Link from '@/components/Controls/Link.vue'
|
||||
|
||||
interface ZoomAccount {
|
||||
name: string
|
||||
account_name: string
|
||||
enabled: boolean
|
||||
member: string
|
||||
account_id: string
|
||||
client_id: string
|
||||
@@ -64,6 +79,13 @@ interface ZoomAccount {
|
||||
|
||||
interface ZoomAccounts {
|
||||
data: ZoomAccount[]
|
||||
reload: () => void
|
||||
insert: {
|
||||
submit: (
|
||||
data: ZoomAccount,
|
||||
options: { onSuccess: () => void; onError: (err: any) => void }
|
||||
) => void
|
||||
}
|
||||
}
|
||||
|
||||
const show = defineModel('show')
|
||||
@@ -71,6 +93,8 @@ const user = inject<User | null>('$user')
|
||||
const zoomAccounts = defineModel<ZoomAccounts>('zoomAccounts')
|
||||
|
||||
const account = reactive({
|
||||
name: '',
|
||||
enabled: false,
|
||||
member: user?.data?.name || '',
|
||||
account_id: '',
|
||||
client_id: '',
|
||||
@@ -87,10 +111,11 @@ const props = defineProps({
|
||||
watch(
|
||||
() => props.accountID,
|
||||
(val) => {
|
||||
console.log(val)
|
||||
if (val != 'new') {
|
||||
zoomAccounts.value?.data.forEach((acc) => {
|
||||
if (acc.name === val) {
|
||||
account.name = acc.name
|
||||
account.enabled = acc.enabled || false
|
||||
account.member = acc.member
|
||||
account.account_id = acc.account_id
|
||||
account.client_id = acc.client_id
|
||||
@@ -100,4 +125,82 @@ watch(
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
watch(show, (val) => {
|
||||
if (!val) {
|
||||
account.name = ''
|
||||
account.enabled = false
|
||||
account.member = user?.data?.name || ''
|
||||
account.account_id = ''
|
||||
account.client_id = ''
|
||||
account.client_secret = ''
|
||||
}
|
||||
})
|
||||
|
||||
const saveAccount = (close) => {
|
||||
if (props.accountID == 'new') {
|
||||
createAccount(close)
|
||||
} else {
|
||||
updateAccount(close)
|
||||
}
|
||||
}
|
||||
|
||||
const createAccount = (close) => {
|
||||
zoomAccounts.value?.insert.submit(
|
||||
{
|
||||
account_name: account.name,
|
||||
...account,
|
||||
},
|
||||
{
|
||||
onSuccess() {
|
||||
zoomAccounts.value?.reload()
|
||||
close()
|
||||
toast.success(__('Zoom Account created successfully'))
|
||||
},
|
||||
onError(err) {
|
||||
close()
|
||||
toast.error(
|
||||
cleanError(err.messages[0]) || __('Error creating Zoom Account')
|
||||
)
|
||||
},
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
const updateAccount = async (close) => {
|
||||
if (props.accountID != account.name) {
|
||||
await renameDoc()
|
||||
}
|
||||
setValue(close)
|
||||
}
|
||||
|
||||
const renameDoc = async () => {
|
||||
await call('frappe.client.rename_doc', {
|
||||
doctype: 'LMS Zoom Settings',
|
||||
old_name: props.accountID,
|
||||
new_name: account.name,
|
||||
})
|
||||
}
|
||||
|
||||
const setValue = (close) => {
|
||||
zoomAccounts.value?.setValue.submit(
|
||||
{
|
||||
...account,
|
||||
name: account.name,
|
||||
},
|
||||
{
|
||||
onSuccess() {
|
||||
zoomAccounts.value?.reload()
|
||||
close()
|
||||
toast.success(__('Zoom Account updated successfully'))
|
||||
},
|
||||
onError(err) {
|
||||
close()
|
||||
toast.error(
|
||||
cleanError(err.messages[0]) || __('Error updating Zoom Account')
|
||||
)
|
||||
},
|
||||
}
|
||||
)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
<div class="text-xl font-semibold text-ink-gray-9">
|
||||
{{ label }}
|
||||
</div>
|
||||
<div class="text-xs text-ink-gray-5">
|
||||
<!-- <div class="text-xs text-ink-gray-5">
|
||||
{{ __(description) }}
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
<div class="flex items-center space-x-5">
|
||||
<Button @click="openTemplateForm('new')">
|
||||
|
||||
@@ -155,13 +155,13 @@ const tabsStructure = computed(() => {
|
||||
type: 'Column Break',
|
||||
},
|
||||
{
|
||||
label: 'Batch Confirmation Template',
|
||||
label: 'Batch Confirmation Email Template',
|
||||
name: 'batch_confirmation_template',
|
||||
doctype: 'Email Template',
|
||||
type: 'Link',
|
||||
},
|
||||
{
|
||||
label: 'Certification Template',
|
||||
label: 'Certification Email Template',
|
||||
name: 'certification_template',
|
||||
doctype: 'Email Template',
|
||||
type: 'Link',
|
||||
|
||||
@@ -48,7 +48,15 @@
|
||||
<ListRow :row="row" v-for="row in zoomAccounts.data">
|
||||
<template #default="{ column, item }">
|
||||
<ListRowItem :item="row[column.key]" :align="column.align">
|
||||
<div class="leading-5 text-sm">
|
||||
<div v-if="column.key == 'enabled'">
|
||||
<Badge v-if="row[column.key]" theme="blue">
|
||||
{{ __('Enabled') }}
|
||||
</Badge>
|
||||
<Badge v-else theme="gray">
|
||||
{{ __('Disabled') }}
|
||||
</Badge>
|
||||
</div>
|
||||
<div v-else class="leading-5 text-sm">
|
||||
{{ row[column.key] }}
|
||||
</div>
|
||||
</ListRowItem>
|
||||
@@ -61,7 +69,7 @@
|
||||
<div class="flex gap-2">
|
||||
<Button
|
||||
variant="ghost"
|
||||
@click="removeTemplate(selections, unselectAll)"
|
||||
@click="removeAccount(selections, unselectAll)"
|
||||
>
|
||||
<Trash2 class="h-4 w-4 stroke-1.5" />
|
||||
</Button>
|
||||
@@ -71,12 +79,18 @@
|
||||
</ListView>
|
||||
</div>
|
||||
</div>
|
||||
<ZoomAccountModal v-model="showForm" v-model:zoomAccounts="zoomAccounts" />
|
||||
<ZoomAccountModal
|
||||
v-model="showForm"
|
||||
v-model:zoomAccounts="zoomAccounts"
|
||||
:accountID="currentAccount"
|
||||
/>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
createListResource,
|
||||
Button,
|
||||
Badge,
|
||||
call,
|
||||
createListResource,
|
||||
ListView,
|
||||
ListHeader,
|
||||
ListHeaderItem,
|
||||
@@ -84,9 +98,11 @@ import {
|
||||
ListRow,
|
||||
ListRowItem,
|
||||
ListSelectBanner,
|
||||
toast,
|
||||
} from 'frappe-ui'
|
||||
import { computed, inject, onMounted, ref } from 'vue'
|
||||
import { Plus, Trash2 } from 'lucide-vue-next'
|
||||
import { cleanError } from '@/utils'
|
||||
import { User } from '@/components/Settings/types'
|
||||
import ZoomAccountModal from '@/components/Modals/ZoomAccountModal.vue'
|
||||
|
||||
@@ -103,6 +119,7 @@ const zoomAccounts = createListResource({
|
||||
doctype: 'LMS Zoom Settings',
|
||||
fields: [
|
||||
'name',
|
||||
'enabled',
|
||||
'member',
|
||||
'member_name',
|
||||
'account_id',
|
||||
@@ -119,7 +136,7 @@ onMounted(() => {
|
||||
const fetchZoomAccounts = () => {
|
||||
if (!user?.data?.is_moderator && !user?.data?.is_evaluator) return
|
||||
|
||||
if (user?.data?.is_evaluator) {
|
||||
if (!user?.data?.is_moderator) {
|
||||
zoomAccounts.update({
|
||||
filters: {
|
||||
member: user.data.name,
|
||||
@@ -134,6 +151,23 @@ const openForm = (accountID: string) => {
|
||||
showForm.value = true
|
||||
}
|
||||
|
||||
const removeAccount = (selections, unselectAll) => {
|
||||
call('lms.lms.api.delete_documents', {
|
||||
doctype: 'LMS Zoom Settings',
|
||||
documents: Array.from(selections),
|
||||
})
|
||||
.then(() => {
|
||||
zoomAccounts.reload()
|
||||
toast.success(__('Email Templates deleted successfully'))
|
||||
unselectAll()
|
||||
})
|
||||
.catch((err) => {
|
||||
toast.error(
|
||||
cleanError(err.messages[0]) || __('Error deleting email templates')
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
const columns = computed(() => {
|
||||
return [
|
||||
{
|
||||
@@ -144,6 +178,11 @@ const columns = computed(() => {
|
||||
label: __('Member'),
|
||||
key: 'member_name',
|
||||
},
|
||||
{
|
||||
label: __('Enabled'),
|
||||
key: 'enabled',
|
||||
align: 'center',
|
||||
},
|
||||
]
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -163,6 +163,11 @@
|
||||
doctype="LMS Zoom Settings"
|
||||
:label="__('Zoom Account')"
|
||||
v-model="batch.zoom_account"
|
||||
:onCreate="
|
||||
(value, close) => {
|
||||
openSettings('Zoom Accounts', close)
|
||||
}
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-5">
|
||||
|
||||
Reference in New Issue
Block a user