Skip to content

Commit a7afe01

Browse files
authored
Ush 1779 to release (#1531)
* Adjustments to make sure translations with media-fields are saved correctly * Cleanup duplicated code
1 parent 681d2e9 commit a7afe01

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

Diff for: apps/web-mzima-client/src/app/post/post-details/post-details.component.ts

+1
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ export class PostDetailsComponent extends BaseComponent implements OnChanges, On
352352
dialogRef.afterClosed().subscribe((response) => {
353353
if (response) {
354354
this.post = response.post;
355+
this.getData(this.post);
355356
this.displayLanguage = response.displayLanguage.code;
356357
}
357358
});

Diff for: apps/web-mzima-client/src/app/post/post-translate/post-translate.component.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ export class PostTranslateComponent implements OnInit {
6464
saveTranslation() {
6565
this.translateForm.disable();
6666
this.post.post_content.forEach((task: any) => {
67-
task.fields
68-
.filter((field: any) => field.key in this.translateForm.controls)
69-
.forEach((field: any) => {
67+
task.fields.forEach((field: any) => {
68+
if (field.key in this.translateForm.controls) {
7069
const translatedValue = this.translateForm.controls[field.key].value;
7170
field.value = field.value || {};
7271
field.value.translations = field.value.translations || {};
@@ -86,16 +85,21 @@ export class PostTranslateComponent implements OnInit {
8685
this.post.translations[this.activeLanguage.code] || {};
8786
this.post.translations[this.activeLanguage.code][field.type] = translatedValue;
8887
}
89-
});
88+
} else if (field.input === 'upload' || field.type === 'media') {
89+
if (field.value) {
90+
field.value = { value: field.value.map((v: any) => v.value) };
91+
}
92+
}
93+
});
9094
});
95+
9196
this.post.enabled_languages = { default: 'en', available: this.enabledLanguages };
9297
delete this.post.completed_stages;
9398

9499
this.postsService.updateTranslations(this.post.id, this.post).subscribe({
95100
next: ({ result }) => {
96101
this.postsService.unlockPost(this.post.id).subscribe();
97102
this.showMessage('Translation saved successfully', 'success');
98-
this.postsService.unlockPost(this.post.id).subscribe();
99103
this.closeModal({ displayLanguage: this.activeLanguage, post: result });
100104
},
101105
error: ({ error }) => {

0 commit comments

Comments
 (0)