Skip to content

Commit

Permalink
fix: type issues (#8413)
Browse files Browse the repository at this point in the history
  • Loading branch information
mertmit committed May 6, 2024
1 parent 2d1c743 commit 08dfcfa
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 249 deletions.
54 changes: 0 additions & 54 deletions packages/nc-gui/components/dlg/WorkspaceDelete.vue

This file was deleted.

7 changes: 3 additions & 4 deletions packages/nc-gui/components/workspace/CollaboratorsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ const selectAll = computed({
const updateCollaborator = async (collab: any, roles: WorkspaceUserRoles) => {
try {
console.log()
await _updateCollaborator(collab.id, roles, currentWorkspace.value.id)
await _updateCollaborator(collab.id, roles, currentWorkspace.value?.id)
message.success('Successfully updated user role')
collaborators.value?.forEach((collaborator) => {
Expand Down Expand Up @@ -95,7 +94,7 @@ onMounted(async () => {
</script>

<template>
<DlgInviteDlg v-model:model-value="inviteDlg" :workspace-id="currentWorkspace.id" type="workspace" />
<DlgInviteDlg v-model:model-value="inviteDlg" :workspace-id="currentWorkspace?.id" type="workspace" />
<div class="nc-collaborator-table-container mt-4 h-[calc(100vh-10rem)]">
<div class="w-full flex justify-between mt-6.5 mb-2">
<a-input v-model:value="userSearchText" class="!max-w-90 !rounded-md mr-4" placeholder="Search members">
Expand Down Expand Up @@ -212,7 +211,7 @@ onMounted(async () => {

<NcMenuItem
class="!text-red-500 !hover:bg-red-50"
@click="removeCollaborator(collab.id, currentWorkspace.id)"
@click="removeCollaborator(collab.id, currentWorkspace?.id)"
>
<MaterialSymbolsDeleteOutlineRounded />
Remove user
Expand Down
190 changes: 1 addition & 189 deletions packages/nc-gui/components/workspace/Settings.vue
Original file line number Diff line number Diff line change
@@ -1,191 +1,3 @@
<script lang="ts" setup>
import { ref, storeToRefs, useGlobal, useI18n, useWorkspace, watch } from '#imports'
const props = defineProps<{
workspaceId?: string
}>()
const { signOut } = useGlobal()
const { t } = useI18n()
const { deleteWorkspace, navigateToWorkspace, updateWorkspace } = useWorkspace()
const { workspacesList, activeWorkspace, workspaces } = storeToRefs(useWorkspace())
const formValidator = ref()
const isConfirmed = ref(false)
const isDeleting = ref(false)
const isErrored = ref(false)
const isTitleUpdating = ref(false)
const isCancelButtonVisible = ref(false)
const form = ref({
title: '',
})
const formRules = {
title: [
{ required: true, message: t('msg.info.wsNameRequired') },
{ min: 3, message: t('msg.info.wsNameMinLength') },
{ max: 50, message: t('msg.info.wsNameMaxLength') },
],
}
const currentWorkspace = computed(() => {
return props.workspaceId ? workspaces.value.get(props.workspaceId) : activeWorkspace.value
})
const onDelete = async () => {
isDeleting.value = true
try {
await deleteWorkspace(currentWorkspace.value.id, { skipStateUpdate: true })
isConfirmed.value = false
isDeleting.value = false
// We only remove the delete workspace from the list after the api call is successful
workspaces.value.delete(currentWorkspace.value.id)
if (workspacesList.value.length > 1) {
// WorkspaceId is provided from the admin Panel. If deleted navigate to the workspace list page
if (!props.workspaceId) {
await navigateToWorkspace(workspacesList.value[0].id)
} else {
// #TODO: @DarkPhoenix2704
// Navigate BackPage
}
} else {
// As signin page will clear the workspaces, we need to check if there are more than one workspace
await signOut(false)
setTimeout(() => {
window.location.href = '/'
}, 100)
}
} finally {
isDeleting.value = false
}
}
const titleChange = async () => {
const valid = await formValidator.value.validate()
if (!valid) return
if (isTitleUpdating.value) return
isTitleUpdating.value = true
isErrored.value = false
try {
await updateWorkspace(currentWorkspace.value.id, {
title: form.value.title,
})
} catch (e: any) {
console.error(e)
} finally {
isTitleUpdating.value = false
isCancelButtonVisible.value = false
}
}
watch(
() => currentWorkspace.value.id,
() => {
form.value.title = currentWorkspace.value.title
},
{
immediate: true,
},
)
watch(
() => form.value.title,
async () => {
try {
isCancelButtonVisible.value = form.value.title !== currentWorkspace.value?.title
isErrored.value = !(await formValidator.value.validate())
} catch (e: any) {
isErrored.value = true
}
},
)
const onCancel = () => {
form.value.title = currentWorkspace.value?.title
}
</script>

<template>
<div class="flex flex-col items-center nc-workspace-settings-settings">
<div class="item flex flex-col w-full">
<div class="font-medium text-base">{{ $t('labels.changeWsName') }}</div>
<a-form ref="formValidator" layout="vertical" no-style :model="form" class="w-full" @finish="titleChange">
<div class="text-gray-500 mt-6 mb-1.5">{{ `${t('objects.workspace')} ${t('general.name')}` }}</div>
<a-form-item name="title" :rules="formRules.title">
<a-input
v-model:value="form.title"
class="w-full !rounded-md !py-1.5"
placeholder="Workspace name"
data-testid="nc-workspace-settings-settings-rename-input"
/>
</a-form-item>
<div class="flex flex-row w-full justify-end mt-8 gap-4">
<NcButton
v-if="isCancelButtonVisible"
type="secondary"
html-type="submit"
data-testid="nc-workspace-settings-settings-rename-cancel"
@click="onCancel"
>
<template #loading> {{ $t('title.renamingWs') }} </template>
{{ $t('general.cancel') }}
</NcButton>
<NcButton
v-e="['c:workspace:settings:rename']"
type="primary"
html-type="submit"
:disabled="isErrored || (form.title && form.title === currentWorkspace.title)"
:loading="isDeleting"
data-testid="nc-workspace-settings-settings-rename-submit"
>
<template #loading> {{ $t('title.renamingWs') }} </template>
{{ $t('title.renameWs') }}
</NcButton>
</div>
</a-form>
</div>
<div class="item flex flex-col">
<div class="font-medium text-base">{{ $t('title.deleteWs') }}</div>
<div class="text-gray-500 mt-2">{{ $t('msg.info.wsDeleteDlg') }}</div>
<div class="flex flex-row mt-8 gap-x-2">
<a-checkbox v-model:checked="isConfirmed" />
<div class="flex">{{ $t('msg.info.userConfirmation') }}</div>
</div>

<div class="flex flex-row w-full justify-end mt-8">
<NcButton
v-e="['c:workspace:settings:delete']"
type="danger"
:disabled="!isConfirmed"
:loading="isDeleting"
@click="onDelete"
>
<template #loading> {{ $t('title.deletingWs') }} </template>
{{ $t('title.deleteWs') }}
</NcButton>
</div>
</div>
</div>
<span />
</template>

<style lang="scss" scoped>
.item-card {
@apply p-6 rounded-2xl border-1 max-w-180 mt-10 min-w-100 w-full;
}
</style>
4 changes: 2 additions & 2 deletions packages/nc-gui/components/workspace/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const tab = computed({
watch(
() => currentWorkspace.value?.title,
(title: string) => {
(title) => {
if (!title) return
const capitalizedTitle = title.charAt(0).toUpperCase() + title.slice(1)
Expand All @@ -60,7 +60,7 @@ onMounted(() => {
until(() => currentWorkspace.value?.id)
.toMatch((v) => !!v)
.then(async () => {
await loadCollaborators({} as any, currentWorkspace.value.id)
await loadCollaborators({} as any, currentWorkspace.value!.id)
})
})
</script>
Expand Down

0 comments on commit 08dfcfa

Please sign in to comment.