Compare commits

...
Author SHA1 Message Date
Muhsin Keloth 9ce1175d9d OpenAI: Add the option to revert to the original text 2023-06-21 16:43:54 +05:30
2 changed files with 29 additions and 3 deletions
@@ -53,17 +53,29 @@
</option> </option>
</select> </select>
</div> </div>
<div v-if="uiFlags.isContentGenerated">
<label>
{{ $t('INTEGRATION_SETTINGS.OPEN_AI.GENERATE_TITLE') }}
</label>
<p>
{{ generatedMessage }}
</p>
</div>
<div class="modal-footer flex-container align-right"> <div class="modal-footer flex-container align-right">
<woot-button variant="clear" size="small" @click="closeDropdown"> <woot-button variant="clear" size="small" @click="closeDropdown">
{{ $t('INTEGRATION_SETTINGS.OPEN_AI.BUTTONS.CANCEL') }} {{ $t('INTEGRATION_SETTINGS.OPEN_AI.BUTTONS.CANCEL') }}
</woot-button> </woot-button>
<woot-button <woot-button
v-if="!uiFlags.isContentGenerated"
:is-loading="uiFlags.rephrase" :is-loading="uiFlags.rephrase"
size="small" size="small"
@click="processEvent('rephrase')" @click="processEvent('rephrase')"
> >
{{ buttonText }} {{ buttonText }}
</woot-button> </woot-button>
<woot-button v-else size="small" @click="replaceText('rephrase')">
{{ $t('INTEGRATION_SETTINGS.OPEN_AI.BUTTONS.REPLACE') }}
</woot-button>
</div> </div>
</div> </div>
</div> </div>
@@ -98,7 +110,9 @@ export default {
rephrase: false, rephrase: false,
reply_suggestion: false, reply_suggestion: false,
summarize: false, summarize: false,
isisContentGenerated: false,
}, },
generatedMessage: '',
showDropdown: false, showDropdown: false,
activeTone: 'professional', activeTone: 'professional',
tones: [ tones: [
@@ -140,6 +154,8 @@ export default {
}, },
methods: { methods: {
toggleDropdown() { toggleDropdown() {
this.uiFlags.isContentGenerated = false;
this.generatedMessage = '';
this.showDropdown = !this.showDropdown; this.showDropdown = !this.showDropdown;
}, },
closeDropdown() { closeDropdown() {
@@ -154,6 +170,11 @@ export default {
}); });
} }
}, },
replaceText(type) {
this.$emit('replace-text', this.generatedMessage || this.message);
this.recordAnalytics({ type, tone: this.activeTone });
this.closeDropdown();
},
async processEvent(type = 'rephrase') { async processEvent(type = 'rephrase') {
this.uiFlags[type] = true; this.uiFlags[type] = true;
try { try {
@@ -167,9 +188,12 @@ export default {
const { const {
data: { message: generatedMessage }, data: { message: generatedMessage },
} = result; } = result;
this.$emit('replace-text', generatedMessage || this.message); this.uiFlags.isContentGenerated = true;
this.closeDropdown(); this.generatedMessage = generatedMessage;
this.recordAnalytics({ type, tone: this.activeTone }); // It the type is not rephrase, replace the text
if (type !== 'rephrase') {
this.replaceText(type);
}
} catch (error) { } catch (error) {
this.showAlert(this.$t('INTEGRATION_SETTINGS.OPEN_AI.GENERATE_ERROR')); this.showAlert(this.$t('INTEGRATION_SETTINGS.OPEN_AI.GENERATE_ERROR'));
} finally { } finally {
@@ -97,8 +97,10 @@
"BUTTONS": { "BUTTONS": {
"GENERATE": "Generate", "GENERATE": "Generate",
"GENERATING": "Generating...", "GENERATING": "Generating...",
"REPLACE": "Replace",
"CANCEL": "Cancel" "CANCEL": "Cancel"
}, },
"GENERATE_TITLE": "Generated Text",
"GENERATE_ERROR": "There was an error processing the content, please try again" "GENERATE_ERROR": "There was an error processing the content, please try again"
}, },
"DELETE": { "DELETE": {