Skip to content

Commit

Permalink
Use mutation correctly in frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
gmercier42 committed Dec 13, 2023
1 parent 1e5b473 commit 9223c8c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
4 changes: 2 additions & 2 deletions webapp/app/pods/components/azure-push-form/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<div local-class='formItem'>
<ProjectSettings::Integrations::Form::DataControlRadio
@allTargetVersions={{this.allTargetVersions}}
@specificVersion={{this.specificVersion}}
@targetVersion={{this.targetVersion}}
@specificVersion={{this.specificVersion}}
@onChangeTargetVersion={{this.setTargetVersion}}
@onChangeSpecificVersion={{this.setSpecificVersion}}
/>
Expand All @@ -26,7 +26,7 @@
{{t 'components.azure_push_form.cancel_button'}}
</LinkTo>

<AsyncButton class='button button--filled' @loading={{this.isSubmitting}} @onClick={{fn this.submit}}>
<AsyncButton class='button button--filled' @loading={{this.isSubmitting}} @onClick={{this.submit}}>
{{t 'components.azure_push_form.push_button'}}
</AsyncButton>
</div>
Expand Down
41 changes: 31 additions & 10 deletions webapp/app/pods/logged-in/project/edit/new/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import IntlService from 'ember-intl/services/intl';
import GlobalState from 'accent-webapp/services/global-state';
import FlashMessages from 'ember-cli-flash/services/flash-messages';
import RouterService from '@ember/routing/router-service';
import ApolloMutate from 'accent-webapp/services/apollo-mutate';
import pushToAzureBlobStorage from 'accent-webapp/queries/push-to-azure-blob-storage';

// interface PushStringsProps {
// targetVersion: string;
// specificVersion: string | null;
// }
const FLASH_MESSAGE_CREATE_SUCCESS =
'pods.versions.new.flash_messages.create_success';
const FLASH_MESSAGE_CREATE_ERROR =
'pods.versions.new.flash_messages.create_error';

export default class AzurePushController extends Controller {
@tracked
Expand All @@ -20,6 +22,9 @@ export default class AzurePushController extends Controller {
@service('intl')
intl: IntlService;

@service('apollo-mutate')
apolloMutate: ApolloMutate;

@service('global-state')
globalState: GlobalState;

Expand All @@ -44,18 +49,34 @@ export default class AzurePushController extends Controller {
}

@action
async pushStrings() {
// const {targetVersion, specificVersion} = props;

await this.delay(1000);
async pushStrings({
targetVersion,
specificVersion,
}: {
targetVersion: string;
specificVersion: string | null;
}) {
const response = await this.apolloMutate.mutate({
mutation: pushToAzureBlobStorage,
variables: {
targetVersion,
specificVersion,
projectId: this.project.id,
},
});

// console.log('TODO: call the pushStrings mutation');
// console.log(props);
if (response.errors) {
this.flashMessages.error(this.intl.t(FLASH_MESSAGE_CREATE_ERROR));
} else {
this.flashMessages.success(this.intl.t(FLASH_MESSAGE_CREATE_SUCCESS));
}

this.router.transitionTo(
'logged-in.project.edit.service-integrations',
this.project.id
);

return response;
}

async delay(ms: number) {
Expand Down

0 comments on commit 9223c8c

Please sign in to comment.