-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4eb714d
commit 6b68909
Showing
6 changed files
with
79 additions
and
70 deletions.
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
42 changes: 24 additions & 18 deletions
42
packages/core/nuxt-theme-module/theme/assets/notifications/cart.ts
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 |
---|---|---|
@@ -1,22 +1,28 @@ | ||
import { useUiNotification } from '../../composables'; | ||
|
||
export const addItem = ({ productName, error, onClick, $i18n }) => { | ||
const { send } = useUiNotification(); | ||
export const cart = (i18n, router) => { | ||
const addItem = ({ productName, error }) => { | ||
const { send } = useUiNotification(); | ||
|
||
if (error) { | ||
send({ | ||
type: 'danger', | ||
message: error | ||
}); | ||
} else { | ||
send({ | ||
type: 'success', | ||
message: productName ? $i18n.t('Successfully added {PRODUCT_NAME} to the cart', { PRODUCT_NAME: productName }) : $i18n.t('Successfully added product to the cart'), | ||
persist: true, | ||
action: { | ||
text: $i18n.t('Go to Checkout'), | ||
onClick | ||
} | ||
}); | ||
} | ||
if (error) { | ||
send({ | ||
type: 'danger', | ||
message: error | ||
}); | ||
} else { | ||
send({ | ||
type: 'success', | ||
message: productName ? i18n.t('Successfully added {PRODUCT_NAME} to the cart', { PRODUCT_NAME: productName }) : i18n.t('Successfully added product to the cart'), | ||
persist: true, | ||
action: { | ||
text: i18n.t('Go to Checkout'), | ||
onClick: () => router.push('/checkout/shipping') | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
return { | ||
addItem | ||
}; | ||
}; |
12 changes: 9 additions & 3 deletions
12
packages/core/nuxt-theme-module/theme/assets/notifications/index.ts
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 |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import * as cart from './cart'; | ||
import { cart } from './cart'; | ||
import { useContext } from '@nuxtjs/composition-api'; | ||
|
||
const sendNotification = { | ||
cart | ||
const sendNotification = () => { | ||
const { app } = useContext(); | ||
const { i18n, router } = app; | ||
|
||
return { | ||
cart: cart(i18n, router) | ||
}; | ||
}; | ||
|
||
export default sendNotification; |
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