Files
speckle-server/packages/frontend-2/components/settings/user/email/SetPrimaryDialog.vue
T
andrewwallacespeckle 4c1ab5f5a0 refactor(fe2): Inputs and Settings Dialog Updates (#2941)
* WIP

* Up to General

* Projects Table

* Other menu items

* Tidy up other inputs

* Refactor Developer Settings to be more modular

* Move buttons to menus

* Minor changes

* Fix build

* Updates from testing

* Fixes from testing
2024-09-12 16:15:27 +01:00

71 lines
1.8 KiB
Vue

<template>
<LayoutDialog
v-model:open="isOpen"
title="Change primary email address"
max-width="xs"
:buttons="dialogButtons"
>
<p class="text-body-xs text-foreground mb-2">
Are you sure you want to make
<span class="font-medium">{{ email }}</span>
your primary email?
</p>
</LayoutDialog>
</template>
<script setup lang="ts">
import type { LayoutDialogButton } from '@speckle/ui-components'
import { useGlobalToast, ToastNotificationType } from '~~/lib/common/composables/toast'
import { settingsSetPrimaryUserEmailMutation } from '~/lib/settings/graphql/mutations'
import { useMutation } from '@vue/apollo-composable'
import {
getFirstErrorMessage,
convertThrowIntoFetchResult
} from '~~/lib/common/helpers/graphql'
const props = defineProps<{
emailId: string
email: string
}>()
const isOpen = defineModel<boolean>('open', { required: true })
const { triggerNotification } = useGlobalToast()
const { mutate: updateMutation } = useMutation(settingsSetPrimaryUserEmailMutation)
const dialogButtons = computed((): LayoutDialogButton[] => [
{
text: 'Cancel',
props: { color: 'outline', outline: true },
onClick: () => {
isOpen.value = false
}
},
{
text: 'Make primary',
props: { color: 'primary' },
onClick: () => {
onSetPrimary()
isOpen.value = false
}
}
])
const onSetPrimary = async () => {
const result = await updateMutation({ input: { id: props.emailId } }).catch(
convertThrowIntoFetchResult
)
if (result?.data) {
triggerNotification({
type: ToastNotificationType.Success,
title: `Made ${props.email} primary`
})
} else {
const errorMessage = getFirstErrorMessage(result?.errors)
triggerNotification({
type: ToastNotificationType.Danger,
title: errorMessage
})
}
}
</script>