Skip to content

Commit

Permalink
fix: Fix crowdin hook list dynamic update - MEED-6899 - Meeds-io/MIPs…
Browse files Browse the repository at this point in the history
  • Loading branch information
AzmiTouil committed May 30, 2024
1 parent 5d6b7c0 commit 43b3bb4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export default {
},
deleteHook() {
return this.$crowdinConnectorService.deleteCrowdinWebHook(this.projectId).then(() => {
this.$root.$emit('crowdin-hooks-updated');
this.$emit('hooksUpdated');
});
},
editCrowdinWebHook(event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
:key="hook.name">
<crowdin-admin-connector-hook
class="full-height"
:hook="hook" />
:hook="hook"
@hooksUpdated="refreshHooks" />
</div>
<template v-if="hasMore">
<v-btn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@
</v-btn>
</div>
</template>
<crowdin-admin-connector-hook-list @updated="webhooksUpdated" />
<crowdin-admin-connector-hook-list ref="childComponentRef" @updated="webhooksUpdated" />
</template>
<crowdin-admin-connector-hook-detail
v-else
:hook="selectedHook"
@close="displayHookDetail = false" />
<crowdin-admin-hook-form-drawer />
<crowdin-admin-hook-form-drawer @hooksUpdated="refreshHooks" />
<crowdin-admin-connection-setting-drawer ref="connectionSettingDrawer" />
<exo-confirm-dialog
ref="deleteConfirmDialog"
Expand Down Expand Up @@ -244,6 +244,9 @@ export default {
forceUpdateWebhooks() {
this.$root.$emit('crowdin-hooks-force-updated');
},
refreshHooks() {
this.$refs.childComponentRef.refreshHooks(false);
},
webhooksUpdated(webhooks){
this.webhooks = webhooks;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,14 @@ export default {
// Get project object from projects using projectId
const project = this.projects.find(p => p.id === this.projectId);
return this.$crowdinConnectorService.saveCrowdinWebHook(project, this.accessToken).then(() => {
this.$root.$emit('crowdin-hooks-updated');
this.$emit('hooksUpdated');
this.close();
}).catch(error => {
this.displayNotificationAlert(error.message, 'error');
}).finally(() => this.loading = false);
} else {
return this.$crowdinConnectorService.updateWebHookAccessToken(this.hookId, this.accessToken).then(() => {
this.$root.$emit('crowdin-hooks-updated');
this.$emit('hooksUpdated');
this.close();
}).finally(() => this.loading = false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ export function saveCrowdinWebHook(project, accessToken) {
},
body: new URLSearchParams(formData).toString(),
}).then(resp => {
if (!resp?.ok) {
if (resp.status === 404 || resp.status === 401) {
return resp.json().then((data) => {
throw new Error(data.message);
});
} else {
throw new Error('Error when saving crowdin webhook');
}
if (resp && resp.ok) {
return resp.json;
} else if (resp.status === 404 || resp.status === 401) {
return resp.json().then((data) => {
throw new Error(data.message);
});
} else {
throw new Error('Error when saving crowdin webhook');
}
});
}
Expand All @@ -109,8 +109,10 @@ export function updateWebHookAccessToken(webHookId, accessToken) {
},
body: new URLSearchParams(formData).toString(),
}).then(resp => {
if (!resp?.ok) {
throw new Error('Error when saving crowdin webhook');
if (resp && resp.ok) {
return resp.json;
} else {
throw new Error('Error when updating crowdin webhook access token');
}
});
}
Expand All @@ -120,7 +122,9 @@ export function deleteCrowdinWebHook(projectId) {
method: 'DELETE',
credentials: 'include',
}).then(resp => {
if (!resp?.ok) {
if (resp && resp.ok) {
return resp.json;
} else {
throw new Error('Error when deleting crowdin webhook');
}
});
Expand Down

0 comments on commit 43b3bb4

Please sign in to comment.