<img width="1439" alt="Screenshot 2024-10-30 at 8 58 12 PM" src="https://github.com/user-attachments/assets/26231270-5e73-40fb-9efa-c661585ebe7c"> Fixes https://linear.app/chatwoot/project/campaign-redesign-f82bede26ca7/overview --------- Co-authored-by: Pranav <pranavrajs@gmail.com> Co-authored-by: Shivam Mishra <scm.mymail@gmail.com>
77 lines
2.0 KiB
Vue
77 lines
2.0 KiB
Vue
<script setup>
|
|
import { ref, computed } from 'vue';
|
|
import { useMapGetter, useStore } from 'dashboard/composables/store';
|
|
import { useAlert } from 'dashboard/composables';
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
import Dialog from 'dashboard/components-next/dialog/Dialog.vue';
|
|
import LiveChatCampaignForm from 'dashboard/components-next/Campaigns/Pages/CampaignPage/LiveChatCampaign/LiveChatCampaignForm.vue';
|
|
|
|
const props = defineProps({
|
|
selectedCampaign: {
|
|
type: Object,
|
|
default: null,
|
|
},
|
|
});
|
|
|
|
const { t } = useI18n();
|
|
const store = useStore();
|
|
|
|
const dialogRef = ref(null);
|
|
const liveChatCampaignFormRef = ref(null);
|
|
|
|
const uiFlags = useMapGetter('campaigns/getUIFlags');
|
|
const isUpdatingCampaign = computed(() => uiFlags.value.isUpdating);
|
|
|
|
const isInvalidForm = computed(
|
|
() => liveChatCampaignFormRef.value?.isSubmitDisabled
|
|
);
|
|
|
|
const selectedCampaignId = computed(() => props.selectedCampaign.id);
|
|
|
|
const updateCampaign = async campaignDetails => {
|
|
try {
|
|
await store.dispatch('campaigns/update', {
|
|
id: selectedCampaignId.value,
|
|
...campaignDetails,
|
|
});
|
|
|
|
useAlert(t('CAMPAIGN.LIVE_CHAT.EDIT.FORM.API.SUCCESS_MESSAGE'));
|
|
dialogRef.value.close();
|
|
} catch (error) {
|
|
const errorMessage =
|
|
error?.response?.message ||
|
|
t('CAMPAIGN.LIVE_CHAT.EDIT.FORM.API.ERROR_MESSAGE');
|
|
useAlert(errorMessage);
|
|
}
|
|
};
|
|
|
|
const handleSubmit = () => {
|
|
updateCampaign(liveChatCampaignFormRef.value.prepareCampaignDetails());
|
|
};
|
|
|
|
defineExpose({ dialogRef });
|
|
</script>
|
|
|
|
<template>
|
|
<Dialog
|
|
ref="dialogRef"
|
|
type="edit"
|
|
:title="t('CAMPAIGN.LIVE_CHAT.EDIT.TITLE')"
|
|
:is-loading="isUpdatingCampaign"
|
|
:disable-confirm-button="isUpdatingCampaign || isInvalidForm"
|
|
overflow-y-auto
|
|
@confirm="handleSubmit"
|
|
>
|
|
<template #form>
|
|
<LiveChatCampaignForm
|
|
ref="liveChatCampaignFormRef"
|
|
mode="edit"
|
|
:selected-campaign="selectedCampaign"
|
|
:show-action-buttons="false"
|
|
@submit="handleSubmit"
|
|
/>
|
|
</template>
|
|
</Dialog>
|
|
</template>
|