Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ yarn-error.log*
# Misc
.DS_Store
out

.yarn
.idea
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# carbon-offset-app
# Order custom actions template

This project was bootstrapped with [Create Wix App](https://www.npmjs.com/package/@wix/create-app).
Read more about it in the [Wix CLI for Apps
Expand Down
8 changes: 8 additions & 0 deletions src/backend/api/orders/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {orders} from '@wix/ecom';
import {getOrder} from "../../orders";

export async function GET(req: Request) {
const _id = new URL(req.url).searchParams.get('orderId') as string;
const order = await getOrder(_id);
return new Response(JSON.stringify(order ?? {}));
}
8 changes: 4 additions & 4 deletions src/backend/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type DataItem = {
export const getDataFromCollection = async ({
dataCollectionId
}: { dataCollectionId: string }) => {
const data = await auth.elevate(items.queryDataItems)({
const data = await items.queryDataItems({
dataCollectionId,
}).find();

Expand All @@ -23,7 +23,7 @@ export const safelyGetItemFromCollection = async ({
itemId
}: { dataCollectionId: string; itemId: string }) => {
try {
const { data } = await auth.elevate(items.getDataItem)(
const { data } = await items.getDataItem(
itemId,
{ dataCollectionId },
);
Expand All @@ -42,7 +42,7 @@ export const upsertDataToCollection = async ({
const existsInCollection = item._id && collection.items.find(existingItem => existingItem._id === item._id);

if (item._id && existsInCollection) {
await auth.elevate(items.updateDataItem)(item._id, {
await items.updateDataItem(item._id, {
dataCollectionId,
dataItem: {
data: {
Expand All @@ -52,7 +52,7 @@ export const upsertDataToCollection = async ({
},
});
} else {
await auth.elevate(items.insertDataItem)({
await items.insertDataItem({
dataCollectionId,
dataItem: {
_id: item._id ?? undefined,
Expand Down
20 changes: 20 additions & 0 deletions src/backend/orders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {orders} from '@wix/ecom';

export async function getOrder(_id: string): Promise<orders.Order> {
//https://dev.wix.com/docs/sdk/backend-modules/ecom/orders/get-order
const order = await orders.getOrder(_id);
return order;
}

export function getBuyerPhoneNumber(order: orders.Order): string | null | undefined {
if(order.billingInfo) return order.billingInfo?.contactDetails?.phone;
else if(order.shippingInfo) return order.recipientInfo?.contactDetails?.phone;
else{
console.log(`No phone number found in order ${JSON.stringify(order)}`);
return null;
}
}

export function getBuyerLanguage(order: orders.Order): string | null | undefined {
return order.buyerLanguage
}
13 changes: 13 additions & 0 deletions src/dashboard/menu-plugins/my-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://dev.wix.com/wix-cli/schemas/dashboard-menu-plugin.json",
"id": "440141de-a590-45f6-87a3-0640a8d845ca",
"title": "Whats Upsell",
"iconKey": "Payment",
"extends": "7c82ce37-3890-4613-9364-03a363c92ebe",
"action": {
"openModal": {
"componentId": "3259acd9-9b12-4f5d-9ace-737a5eb73876",
"componentParams": {}
}
}
}
7 changes: 7 additions & 0 deletions src/dashboard/modals/whatup-modals/modal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://dev.wix.com/wix-cli/schemas/dashboard-modal.json",
"id": "3259acd9-9b12-4f5d-9ace-737a5eb73876",
"title": "message-modal",
"width": 850,
"height": 900
}
62 changes: 62 additions & 0 deletions src/dashboard/modals/whatup-modals/modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React, { type FC, useState } from 'react';
import { dashboard } from '@wix/dashboard';
import {
WixDesignSystemProvider,
Text,
Box,
CustomModalLayout, Dropdown,
} from '@wix/design-system';
import '@wix/design-system/styles.global.css';
import { width, height } from './modal.json';

// To open your modal, call `openModal` with your modal id.
// e.g.
// import { dashboard } from '@wix/dashboard';
// function MyComponent() {
// return <button onClick={() => dashboard.openModal('3259acd9-9b12-4f5d-9ace-737a5eb73876')}>Open Modal</button>;
// }
const Modal: FC = (props: {orderId: string}) => {
const orderId = props.orderId;
console.log('orderId:', orderId);

const [selectedProduct, setSelectedProduct] = useState('');

const productOptions = [
{ id: 'product1', value: 'Product 1' },
{ id: 'product2', value: 'Product 2' },
{ id: 'product3', value: 'Product 3' },
];

return (
<WixDesignSystemProvider features={{ newColorsBranding: true }}>
<CustomModalLayout
// width={width}
// maxHeight={height}
primaryButtonText="Save"
secondaryButtonText="Cancel"
onCloseButtonClick={() => dashboard.closeModal()}
primaryButtonOnClick={() => {
console.log('Selected product:', selectedProduct);
dashboard.closeModal();
}} secondaryButtonOnClick={() => dashboard.closeModal()}
title="Upsell with whatsup"
subtitle="selcet products to resale"
content={
<Box direction="vertical" align="stretch" margin="medium">
<Dropdown
placeholder="Select a product"
options={productOptions}
selectedId={selectedProduct}
onSelect={(option) => setSelectedProduct(option.id)}
/>
<Box marginTop="medium" align="center">
<Text>Wix CLI Modal</Text>
</Box>
</Box>
}
/>
</WixDesignSystemProvider>
);
};

export default Modal;
4 changes: 2 additions & 2 deletions wix.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://dev.wix.com/wix-cli/schemas/wix-config.json",
"appId": "a21a2d2f-e642-4195-adcc-ccdd389ba3c0",
"projectId": "standalone-carbon-offset"
"appId": "9f95a5e9-9723-4183-8025-3e15bcad4960",
"projectId": "custom-order-action-template"
}