-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented: code to add functionality to subscribe or unsubscribe a webhook(#2ftb11u) #191
Merged
Merged
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
43543b8
Implemented | Web hooks card on Product View Page
939cf6a
Improved: Internationalized webhooks card labels on Product View Page
4e8d0fe
Implemented: Webhooks services and store, Implemented: Webhooks toggl…
rvutd 97f9731
Impproved: Login and naming convections in webhooks store and Product…
rvutd e92f7bf
Improved: naming convenction, removed unnecessary code and other upda…
rvutd 1f0c930
Improved: naming convenctions
rvutd 446957c
Imporve: Removed s from webhooks
rvutd 96733de
Improved: naming convenctions
rvutd d377c3c
Implemented: Webhook update functionality flow
rvutd 136e593
Improved: Logic for storing webhooks in store ann Implemented: webser…
rvutd 53e4cc2
Issue: currently working on it
rvutd 0fb3921
Un-resolved Issue: When user click on toggle and if service fails tog…
rvutd f0de5c6
Merge branch 'job-manager/#175' into #2ftb11u
ymaheshwari1 7b17a74
Implemented: service to subscribe the file state update webhook(#2ftb…
ymaheshwari1 bb29f7c
Implemented: action to subscribe the webhook and updated the cached s…
ymaheshwari1 fa1dc31
Implemented: UI for the fileStatusUpdate webhook(#2ftb11u)
ymaheshwari1 898640c
Removed: unwanted console statements(#2ftb11u)
ymaheshwari1 5540e7a
Removed: the shopify config id passed to the fetch webhooks action(#2…
ymaheshwari1 02d5488
Improved: code to define a single method to subscribe and unsubscribe…
ymaheshwari1 9112e6c
Improved: code to define an object consisting of job id and correspon…
ymaheshwari1 4b3f178
Improved: code to defined a single action to subscribe webhooks and d…
ymaheshwari1 45af475
Improved: code to define the checked prop to use a computed property …
ymaheshwari1 99507bf
Removed: unwanted mutation and its type, also updated the service nam…
ymaheshwari1 93a7e89
Improved: code to defined a variable and stored the webhook topic in …
ymaheshwari1 4a8b412
Added: static text in en.json file(#2ftb11u)
ymaheshwari1 9dd3f05
Merge branch 'main' of https://github.com/hotwax/job-manager into #2f…
ymaheshwari1 6c0f514
Removed: an extra check when calculating whether a webhook is subscri…
ymaheshwari1 dabd8ec
Removed: unwanted state key from the webhook store module(#2ftb11u)
ymaheshwari1 f645c0d
Improved: paramter name from id to enum and added todos on the missin…
ymaheshwari1 eb7eda4
Improved: the variable name from topic to webhook(#2ftb11u)
ymaheshwari1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import api from '@/api' | ||
|
||
const fetchShopifyWebhooks = async (payload?: any): Promise <any> => { | ||
return api({ | ||
url: "/service/getShopifyWebhooks", | ||
method: "post", | ||
data: payload | ||
}); | ||
} | ||
|
||
// TODO: add the service endpoint for the new order webhook | ||
const subscribeNewOrderWebhook = async (payload?: any): Promise <any> => { | ||
return api ({ | ||
url: '', | ||
method: 'post', | ||
data: payload | ||
}) | ||
} | ||
|
||
// TODO: add the service endpoint for the cancelled order webhook | ||
const subscribeCancelledOrderWebhook = async (payload?: any): Promise <any> => { | ||
return api ({ | ||
url: '', | ||
method: 'post', | ||
data: payload | ||
}) | ||
} | ||
|
||
// TODO: add the service endpoint for the payment status webhook | ||
const subscribePaymentStatusWebhook = async (payload?: any): Promise <any> => { | ||
return api ({ | ||
url: '', | ||
method: 'post', | ||
data: payload | ||
}) | ||
} | ||
|
||
// TODO: add the service endpoint for the order return webhook | ||
const subscribeReturnWebhook = async (payload?: any): Promise <any> => { | ||
return api ({ | ||
url: '', | ||
method: 'post', | ||
data: payload | ||
}) | ||
} | ||
|
||
// TODO: add the service endpoint for the new product webhook | ||
const subscribeNewProductsWebhook = async (payload?: any): Promise <any> => { | ||
return api ({ | ||
url: '', | ||
method: 'post', | ||
data: payload | ||
}) | ||
} | ||
|
||
const subscribeDeleteProductsWebhook = async (payload?: any): Promise <any> => { | ||
return api ({ | ||
url: 'service/subscribeProductDeleteWebhook', | ||
method: 'post', | ||
data: payload | ||
}) | ||
} | ||
|
||
const subscribeFileStatusUpdateWebhook = async (payload?: any): Promise <any> => { | ||
return api ({ | ||
url: 'service/subscribeFileStatusUpdateWebhook', | ||
method: 'post', | ||
data: payload | ||
}) | ||
} | ||
|
||
const unsubscribeWebhook = async (payload?: any): Promise <any> => { | ||
return api ({ | ||
url: 'service/removeShopifyWebhook', | ||
method: 'post', | ||
data: payload | ||
}) | ||
} | ||
|
||
export const WebhookService = { | ||
fetchShopifyWebhooks, | ||
subscribeNewOrderWebhook, | ||
subscribeCancelledOrderWebhook, | ||
subscribeFileStatusUpdateWebhook, | ||
subscribePaymentStatusWebhook, | ||
subscribeReturnWebhook, | ||
subscribeNewProductsWebhook, | ||
subscribeDeleteProductsWebhook, | ||
unsubscribeWebhook | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default interface WebhookState { | ||
cached: any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { ActionTree } from "vuex"; | ||
import RootState from "@/store/RootState"; | ||
import WebhookState from "./WebhookState"; | ||
import { WebhookService } from "@/services/WebhookService"; | ||
import { hasError, showToast } from "@/utils"; | ||
import * as types from './mutations-types' | ||
import { translate } from '@/i18n' | ||
|
||
const actions: ActionTree<WebhookState, RootState> = { | ||
async fetchWebhooks({ commit }) { | ||
await WebhookService.fetchShopifyWebhooks({ shopifyConfigId: this.state.user.shopifyConfig }).then(resp => { | ||
if (resp.status == 200 && resp.data.webhooks?.length > 0 && !hasError(resp)) { | ||
const webhooks = resp.data.webhooks; | ||
const topics: any = {} | ||
webhooks.map((topic: any) => { | ||
topics[topic.topic] = topic | ||
}) | ||
commit(types.WEBHOOK_UPDATED, topics) | ||
} | ||
}).catch(err => console.error(err)) | ||
}, | ||
async unsubscribeWebhook({ dispatch }, payload: any) { | ||
|
||
let resp; | ||
|
||
try { | ||
resp = await WebhookService.unsubscribeWebhook(payload) | ||
if (resp.status === 200 && !hasError(resp)) { | ||
showToast(translate("Webhook unsubscribed successfully")); | ||
} | ||
} catch(err) { | ||
console.log(err) | ||
showToast(translate("Something went wrong")); | ||
} finally { | ||
dispatch('fetchWebhooks') | ||
} | ||
}, | ||
async subscribeWebhook({ dispatch }, id: string) { | ||
|
||
// stores the webhook service that needs to be called on the basis of current webhook selected, doing | ||
// so as we have defined separate service for different webhook subscription | ||
const webhookMethods = { | ||
'NEW_ORDERS': WebhookService.subscribeNewOrderWebhook, | ||
'CANCELLED_ORDERS': WebhookService.subscribeCancelledOrderWebhook, | ||
'PAYMENT_STATUS':WebhookService.subscribePaymentStatusWebhook, | ||
'RETURNS': WebhookService.subscribeReturnWebhook, | ||
'NEW_PRODUCTS': WebhookService.subscribeNewProductsWebhook, | ||
'DELETE_PRODUCTS': WebhookService.subscribeDeleteProductsWebhook, | ||
'BULK_OPERATIONS_FINISH': WebhookService.subscribeFileStatusUpdateWebhook | ||
} as any | ||
const webhookMethod: any = webhookMethods[id]; | ||
|
||
if (!webhookMethod) { | ||
showToast(translate("Configuration missing")); | ||
return; | ||
} | ||
|
||
let resp; | ||
|
||
try { | ||
resp = await webhookMethod({ shopifyConfigId: this.state.user.shopifyConfig }) | ||
|
||
if (resp.status == 200 && !hasError(resp)) { | ||
showToast(translate('Webhook subscribed successfully')) | ||
} else { | ||
showToast(translate('Something went wrong')) | ||
console.error(resp) | ||
} | ||
} catch (err) { | ||
showToast(translate('Something went wrong')) | ||
console.error(err); | ||
} finally { | ||
await dispatch('fetchWebhooks') | ||
} | ||
} | ||
} | ||
|
||
export default actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { GetterTree } from "vuex"; | ||
import RootState from "@/store/RootState"; | ||
import WebhookState from "./WebhookState"; | ||
|
||
const getters: GetterTree<WebhookState, RootState> = { | ||
getCachedWebhook: (state) => state.cached | ||
} | ||
|
||
export default getters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Module } from 'vuex' | ||
import WebhookState from './WebhookState' | ||
import RootState from '@/store/RootState' | ||
import getters from './getters' | ||
import mutations from './mutations' | ||
import actions from './actions' | ||
|
||
const webhookModule: Module<WebhookState, RootState> = { | ||
namespaced: true, | ||
state: { | ||
cached: {} | ||
}, | ||
getters, | ||
actions, | ||
mutations, | ||
} | ||
|
||
export default webhookModule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const SN_WEBHOOK = 'webhook' | ||
export const WEBHOOK_UPDATED = SN_WEBHOOK + '/WEBHOOK_UPDATED' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { MutationTree } from "vuex"; | ||
import WebhookState from "./WebhookState"; | ||
import * as types from './mutations-types' | ||
|
||
const mutations: MutationTree<WebhookState> = { | ||
[types.WEBHOOK_UPDATED] (state, payload: any) { | ||
state.cached = payload | ||
} | ||
} | ||
|
||
export default mutations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.