2022-09-27 09:13:20 +00:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { apiClient } from "@/utils/api-client";
|
|
|
|
import type { User } from "@halo-dev/api-client";
|
2024-05-24 07:18:51 +00:00
|
|
|
import { VButton, VModal, VSpace } from "@halo-dev/components";
|
2022-09-27 09:13:20 +00:00
|
|
|
import SubmitButton from "@/components/button/SubmitButton.vue";
|
2023-03-30 15:30:14 +00:00
|
|
|
import { ref } from "vue";
|
2022-09-27 09:13:20 +00:00
|
|
|
|
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
|
|
|
user?: User;
|
|
|
|
}>(),
|
|
|
|
{
|
|
|
|
user: undefined,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
(event: "close"): void;
|
|
|
|
}>();
|
|
|
|
|
2024-05-27 08:56:57 +00:00
|
|
|
const modal = ref<InstanceType<typeof VModal> | null>(null);
|
2022-09-27 09:13:20 +00:00
|
|
|
const selectedRole = ref("");
|
2024-05-24 07:18:51 +00:00
|
|
|
const isSubmitting = ref(false);
|
2022-09-27 09:13:20 +00:00
|
|
|
|
|
|
|
const handleGrantPermission = async () => {
|
|
|
|
try {
|
2024-05-24 07:18:51 +00:00
|
|
|
isSubmitting.value = true;
|
2022-09-27 09:13:20 +00:00
|
|
|
await apiClient.user.grantPermission({
|
2022-11-17 02:38:22 +00:00
|
|
|
name: props.user?.metadata.name as string,
|
2022-09-27 09:13:20 +00:00
|
|
|
grantRequest: {
|
|
|
|
roles: [selectedRole.value],
|
|
|
|
},
|
|
|
|
});
|
2024-05-24 07:18:51 +00:00
|
|
|
modal.value?.close();
|
2022-09-27 09:13:20 +00:00
|
|
|
} catch (error) {
|
2023-02-17 06:36:15 +00:00
|
|
|
console.error("Failed to grant permission to user", error);
|
2022-09-27 09:13:20 +00:00
|
|
|
} finally {
|
2024-05-24 07:18:51 +00:00
|
|
|
isSubmitting.value = false;
|
2022-09-27 09:13:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<VModal
|
2024-05-24 07:18:51 +00:00
|
|
|
ref="modal"
|
2023-03-23 08:54:33 +00:00
|
|
|
:title="$t('core.user.grant_permission_modal.title')"
|
2022-09-27 09:13:20 +00:00
|
|
|
:width="500"
|
2024-05-24 07:18:51 +00:00
|
|
|
@close="emit('close')"
|
2022-09-27 09:13:20 +00:00
|
|
|
>
|
|
|
|
<FormKit
|
|
|
|
id="grant-permission-form"
|
|
|
|
name="grant-permission-form"
|
|
|
|
:config="{ validationVisibility: 'submit' }"
|
|
|
|
type="form"
|
|
|
|
@submit="handleGrantPermission"
|
|
|
|
>
|
|
|
|
<FormKit
|
|
|
|
v-model="selectedRole"
|
2023-03-23 08:54:33 +00:00
|
|
|
:label="$t('core.user.grant_permission_modal.fields.role.label')"
|
2023-03-30 15:30:14 +00:00
|
|
|
type="roleSelect"
|
2022-09-27 09:13:20 +00:00
|
|
|
></FormKit>
|
|
|
|
</FormKit>
|
|
|
|
<template #footer>
|
|
|
|
<VSpace>
|
|
|
|
<SubmitButton
|
2024-05-24 07:18:51 +00:00
|
|
|
:loading="isSubmitting"
|
2022-09-27 09:13:20 +00:00
|
|
|
type="secondary"
|
2023-03-23 08:54:33 +00:00
|
|
|
:text="$t('core.common.buttons.submit')"
|
2022-09-27 09:13:20 +00:00
|
|
|
@submit="$formkit.submit('grant-permission-form')"
|
|
|
|
>
|
|
|
|
</SubmitButton>
|
2024-05-24 07:18:51 +00:00
|
|
|
<VButton @click="modal?.close()">
|
2023-03-23 08:54:33 +00:00
|
|
|
{{ $t("core.common.buttons.cancel_and_shortcut") }}
|
|
|
|
</VButton>
|
2022-09-27 09:13:20 +00:00
|
|
|
</VSpace>
|
|
|
|
</template>
|
|
|
|
</VModal>
|
|
|
|
</template>
|