feat: Ability to reset api_access_token (#11565)
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: iamsivin <iamsivin@gmail.com> Co-authored-by: Shivam Mishra <scm.mymail@gmail.com>
This commit is contained in:
@@ -228,7 +228,20 @@ const initializeForm = () => {
|
||||
|
||||
const onCopyToken = async value => {
|
||||
await copyTextToClipboard(value);
|
||||
useAlert(t('COMPONENTS.CODE.COPY_SUCCESSFUL'));
|
||||
useAlert(t('AGENT_BOTS.ACCESS_TOKEN.COPY_SUCCESSFUL'));
|
||||
};
|
||||
|
||||
const onResetToken = async () => {
|
||||
const response = await store.dispatch(
|
||||
'agentBots/resetAccessToken',
|
||||
props.selectedBot.id
|
||||
);
|
||||
if (response) {
|
||||
accessToken.value = response.access_token;
|
||||
useAlert(t('AGENT_BOTS.ACCESS_TOKEN.RESET_SUCCESS'));
|
||||
} else {
|
||||
useAlert(t('AGENT_BOTS.ACCESS_TOKEN.RESET_ERROR'));
|
||||
}
|
||||
};
|
||||
|
||||
const closeModal = () => {
|
||||
@@ -312,7 +325,18 @@ defineExpose({ dialogRef });
|
||||
>
|
||||
{{ $t('AGENT_BOTS.ACCESS_TOKEN.TITLE') }}
|
||||
</label>
|
||||
<AccessToken :value="accessToken" @on-copy="onCopyToken" />
|
||||
<AccessToken
|
||||
v-if="type === MODAL_TYPES.EDIT"
|
||||
:value="accessToken"
|
||||
@on-copy="onCopyToken"
|
||||
@on-reset="onResetToken"
|
||||
/>
|
||||
<AccessToken
|
||||
v-else
|
||||
:value="accessToken"
|
||||
:show-reset-button="false"
|
||||
@on-copy="onCopyToken"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-end w-full gap-2 px-0 py-2">
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue';
|
||||
import FormButton from 'v3/components/Form/Button.vue';
|
||||
import NextButton from 'dashboard/components-next/button/Button.vue';
|
||||
import ConfirmButton from 'dashboard/components-next/button/ConfirmButton.vue';
|
||||
|
||||
const props = defineProps({
|
||||
value: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
value: { type: String, default: '' },
|
||||
showResetButton: { type: Boolean, default: true },
|
||||
});
|
||||
const emit = defineEmits(['onCopy']);
|
||||
|
||||
const emit = defineEmits(['onCopy', 'onReset']);
|
||||
|
||||
const inputType = ref('password');
|
||||
|
||||
const toggleMasked = () => {
|
||||
inputType.value = inputType.value === 'password' ? 'text' : 'password';
|
||||
};
|
||||
@@ -20,6 +23,10 @@ const maskIcon = computed(() => {
|
||||
const onClick = () => {
|
||||
emit('onCopy', props.value);
|
||||
};
|
||||
|
||||
const onReset = () => {
|
||||
emit('onReset');
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -38,7 +45,7 @@ const onClick = () => {
|
||||
>
|
||||
<template #masked>
|
||||
<button
|
||||
class="absolute top-1.5 ltr:right-0.5 rtl:left-0.5"
|
||||
class="absolute top-0 bottom-0 ltr:right-0.5 rtl:left-0.5"
|
||||
type="button"
|
||||
@click="toggleMasked"
|
||||
>
|
||||
@@ -46,15 +53,28 @@ const onClick = () => {
|
||||
</button>
|
||||
</template>
|
||||
</woot-input>
|
||||
<FormButton
|
||||
type="button"
|
||||
size="large"
|
||||
icon="text-copy"
|
||||
variant="outline"
|
||||
color-scheme="secondary"
|
||||
@click="onClick"
|
||||
>
|
||||
{{ $t('PROFILE_SETTINGS.FORM.ACCESS_TOKEN.COPY') }}
|
||||
</FormButton>
|
||||
<div class="flex flex-row gap-2">
|
||||
<NextButton
|
||||
:label="$t('PROFILE_SETTINGS.FORM.ACCESS_TOKEN.COPY')"
|
||||
slate
|
||||
outline
|
||||
type="button"
|
||||
icon="i-lucide-copy"
|
||||
class="rounded-xl"
|
||||
@click="onClick"
|
||||
/>
|
||||
<ConfirmButton
|
||||
v-if="showResetButton"
|
||||
:label="$t('PROFILE_SETTINGS.FORM.ACCESS_TOKEN.RESET')"
|
||||
:confirm-label="$t('PROFILE_SETTINGS.FORM.ACCESS_TOKEN.CONFIRM_RESET')"
|
||||
:confirm-hint="$t('PROFILE_SETTINGS.FORM.ACCESS_TOKEN.CONFIRM_HINT')"
|
||||
color="slate"
|
||||
confirm-color="ruby"
|
||||
variant="outline"
|
||||
icon="i-lucide-key-round"
|
||||
class="rounded-xl"
|
||||
@click="onReset"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -181,6 +181,14 @@ export default {
|
||||
await copyTextToClipboard(value);
|
||||
useAlert(this.$t('COMPONENTS.CODE.COPY_SUCCESSFUL'));
|
||||
},
|
||||
async resetAccessToken() {
|
||||
const success = await this.$store.dispatch('resetAccessToken');
|
||||
if (success) {
|
||||
useAlert(this.$t('PROFILE_SETTINGS.FORM.ACCESS_TOKEN.RESET_SUCCESS'));
|
||||
} else {
|
||||
useAlert(this.$t('PROFILE_SETTINGS.FORM.ACCESS_TOKEN.RESET_ERROR'));
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@@ -281,7 +289,11 @@ export default {
|
||||
)
|
||||
"
|
||||
>
|
||||
<AccessToken :value="currentUser.access_token" @on-copy="onCopyToken" />
|
||||
<AccessToken
|
||||
:value="currentUser.access_token"
|
||||
@on-copy="onCopyToken"
|
||||
@on-reset="resetAccessToken"
|
||||
/>
|
||||
</FormSection>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user