parent
4632ff71b6
commit
da024f8cec
@ -0,0 +1,23 @@
|
|||||||
|
import {request} from "@strapi/helper-plugin";
|
||||||
|
import {get, has, isEmpty, pickBy, set} from "lodash";
|
||||||
|
import {auth} from '@strapi/helper-plugin';
|
||||||
|
|
||||||
|
const productsRequests = {
|
||||||
|
getProducts: async () => {
|
||||||
|
try {
|
||||||
|
const response = await request("/vendors/products/list", {method: "GET", headers: {
|
||||||
|
Authorization: `Bearer ${auth.getToken()}`
|
||||||
|
}});
|
||||||
|
|
||||||
|
return response;
|
||||||
|
} catch (e) {
|
||||||
|
return {
|
||||||
|
error: true,
|
||||||
|
message: e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
},
|
||||||
|
};
|
||||||
|
export default productsRequests;
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* HomePage
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
import { EmptyStateLayout, Button } from '@strapi/design-system';
|
||||||
|
import {Cross, Plus} from "@strapi/icons";
|
||||||
|
|
||||||
|
const CatalogProductEmpty = () => {
|
||||||
|
return (
|
||||||
|
<EmptyStateLayout content="You don't have any content yet..." action={<Button variant="secondary" startIcon={<Plus />}>
|
||||||
|
Create your first product
|
||||||
|
</Button>} />
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CatalogProductEmpty;
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* HomePage
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, {useState} from 'react';
|
||||||
|
import {HeaderLayout, Button, Link} from '@strapi/design-system';
|
||||||
|
import {ArrowLeft, Pencil, Plus} from "@strapi/icons";
|
||||||
|
import getPluginRoute from "../../../../utils/base-route";
|
||||||
|
|
||||||
|
const CatalogProductHeader = ({total}) => {
|
||||||
|
const [isVisible, setIsVisible] = useState(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<HeaderLayout navigationAction={<Link startIcon={<ArrowLeft/>} to={getPluginRoute()}>
|
||||||
|
Go back
|
||||||
|
</Link>} primaryAction={<Button startIcon={<Plus/>} onClick={() => setIsVisible(true)}>
|
||||||
|
Add an entry
|
||||||
|
</Button>} secondaryAction={<Button variant="tertiary" startIcon={<Pencil/>}>
|
||||||
|
Edit
|
||||||
|
</Button>} title="Products" subtitle={total + " entries found"} as="h2"/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CatalogProductHeader;
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* HomePage
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
import {Pagination, PreviousLink, PageLink, NextLink} from '@strapi/design-system';
|
||||||
|
import {NavLink} from 'react-router-dom';
|
||||||
|
|
||||||
|
const CatalogProductPagination = () => {
|
||||||
|
|
||||||
|
const buildUrlWithPageParams = (page: number) => {
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
const searchParams = new URLSearchParams(url.searchParams);
|
||||||
|
searchParams.set("page", page.toString());
|
||||||
|
return `${url.pathname.replace('admin/', '')}?${searchParams.toString()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Pagination>
|
||||||
|
<PreviousLink as={NavLink} to={buildUrlWithPageParams(1)}>
|
||||||
|
Previous
|
||||||
|
</PreviousLink>
|
||||||
|
<PageLink as={NavLink} to={buildUrlWithPageParams(1)}>
|
||||||
|
1
|
||||||
|
</PageLink>
|
||||||
|
<PageLink as={NavLink} to={buildUrlWithPageParams(2)}>
|
||||||
|
2
|
||||||
|
</PageLink>
|
||||||
|
<NextLink as={NavLink} to={buildUrlWithPageParams(2)}>
|
||||||
|
Next page
|
||||||
|
</NextLink>
|
||||||
|
</Pagination>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CatalogProductPagination;
|
||||||
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* HomePage
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
Thead,
|
||||||
|
Tbody,
|
||||||
|
Tr,
|
||||||
|
Td,
|
||||||
|
Th,
|
||||||
|
BaseCheckbox,
|
||||||
|
Typography,
|
||||||
|
Avatar,
|
||||||
|
Flex,
|
||||||
|
IconButton,
|
||||||
|
VisuallyHidden,
|
||||||
|
Box
|
||||||
|
} from '@strapi/design-system';
|
||||||
|
import {Pencil, Plus, Trash} from "@strapi/icons";
|
||||||
|
|
||||||
|
const CatalogProductTable = ({items}) => {
|
||||||
|
const ROW_COUNT = 6;
|
||||||
|
const COL_COUNT = 10;
|
||||||
|
|
||||||
|
const entry = {
|
||||||
|
cover: 'https://avatars.githubusercontent.com/u/3874873?v=4',
|
||||||
|
description: 'Chez Léon is a human sized Parisian',
|
||||||
|
category: 'French cuisine',
|
||||||
|
contact: 'Leon Lafrite'
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Table colCount={COL_COUNT} rowCount={ROW_COUNT}>
|
||||||
|
<Thead>
|
||||||
|
<Tr>
|
||||||
|
<Th>
|
||||||
|
<BaseCheckbox aria-label="Select all entries"/>
|
||||||
|
</Th>
|
||||||
|
<Th>
|
||||||
|
<Typography variant="sigma">ID</Typography>
|
||||||
|
</Th>
|
||||||
|
<Th>
|
||||||
|
<Typography variant="sigma">Cover</Typography>
|
||||||
|
</Th>
|
||||||
|
<Th>
|
||||||
|
<Typography variant="sigma">Description</Typography>
|
||||||
|
</Th>
|
||||||
|
<Th>
|
||||||
|
<Typography variant="sigma">Categories</Typography>
|
||||||
|
</Th>
|
||||||
|
<Th>
|
||||||
|
<Typography variant="sigma">Contact</Typography>
|
||||||
|
</Th>
|
||||||
|
<Th>
|
||||||
|
<VisuallyHidden>Actions</VisuallyHidden>
|
||||||
|
</Th>
|
||||||
|
</Tr>
|
||||||
|
</Thead>
|
||||||
|
<Tbody>
|
||||||
|
{items.map(entry => <Tr key={entry.id}>
|
||||||
|
<Td>
|
||||||
|
<BaseCheckbox aria-label={`Select ${entry.contact}`}/>
|
||||||
|
</Td>
|
||||||
|
<Td>
|
||||||
|
<Typography textColor="neutral800">{entry.id}</Typography>
|
||||||
|
</Td>
|
||||||
|
<Td>
|
||||||
|
<Avatar src={entry.cover} alt={entry.contact}/>
|
||||||
|
</Td>
|
||||||
|
<Td>
|
||||||
|
<Typography textColor="neutral800">{entry.description}</Typography>
|
||||||
|
</Td>
|
||||||
|
<Td>
|
||||||
|
<Typography textColor="neutral800">{entry.category}</Typography>
|
||||||
|
</Td>
|
||||||
|
<Td>
|
||||||
|
<Typography textColor="neutral800">{entry.contact}</Typography>
|
||||||
|
</Td>
|
||||||
|
<Td>
|
||||||
|
<Flex>
|
||||||
|
<IconButton onClick={() => console.log('edit')} label="Edit" noBorder icon={<Pencil/>}/>
|
||||||
|
<Box paddingLeft={1}>
|
||||||
|
<IconButton onClick={() => console.log('delete')} label="Delete" noBorder icon={<Trash/>}/>
|
||||||
|
</Box>
|
||||||
|
</Flex>
|
||||||
|
</Td>
|
||||||
|
</Tr>)}
|
||||||
|
</Tbody>
|
||||||
|
</Table>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CatalogProductTable;
|
||||||
@ -1 +1,3 @@
|
|||||||
{}
|
{
|
||||||
|
"vendors.plugin.name": "Vendors Admin"
|
||||||
|
}
|
||||||
|
|||||||
@ -1 +1,3 @@
|
|||||||
{}
|
{
|
||||||
|
"vendors.plugin.name": "Boutique Admin"
|
||||||
|
}
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
const PLUGIN_ROUTE = '/plugins/vendors';
|
||||||
|
|
||||||
|
export default function getPluginRoute() {
|
||||||
|
return PLUGIN_ROUTE;
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
export enum ROUTES {
|
||||||
|
CatalogProducts = '/catalog/products',
|
||||||
|
CatalogCategories = '/catalog/categories',
|
||||||
|
CatalogFilters = '/catalog/filters',
|
||||||
|
CustomersOrders = '/customers/orders',
|
||||||
|
CustomersCoupons = '/customers/coupons',
|
||||||
|
ParametersGeneral = '/settings/general',
|
||||||
|
ParametersProducts = '/settings/products',
|
||||||
|
ParametersShipping = '/settings/shipping',
|
||||||
|
ParametersPayments = '/settings/payments',
|
||||||
|
ParametersAccounts = '/settings/accounts',
|
||||||
|
ParametersEmails = '/settings/emails',
|
||||||
|
ParametersIntegration = '/settings/integration',
|
||||||
|
ParametersAdvanced = '/settings/advanced',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum PERMISSION {
|
||||||
|
CatalogProductsRead = 'plugin::vendors.read'
|
||||||
|
}
|
||||||
@ -1,5 +1,20 @@
|
|||||||
import { Strapi } from '@strapi/strapi';
|
import { Strapi } from '@strapi/strapi';
|
||||||
|
|
||||||
export default ({ strapi }: { strapi: Strapi }) => {
|
const RBAC_ACTIONS = [
|
||||||
// bootstrap phase
|
{
|
||||||
|
section: 'plugins',
|
||||||
|
displayName: `Access to vendor's administration page`,
|
||||||
|
uid: 'read',
|
||||||
|
pluginName: 'vendors',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export default async ({ strapi }: { strapi: any }) => {
|
||||||
|
await strapi.admin.services.permission.actionProvider.registerMany(RBAC_ACTIONS);
|
||||||
|
|
||||||
|
strapi.store({
|
||||||
|
environment: '',
|
||||||
|
type: 'plugin',
|
||||||
|
name: 'vendors',
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import myController from './my-controller';
|
import products from './products';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
myController,
|
products,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
import { Strapi } from '@strapi/strapi';
|
|
||||||
|
|
||||||
export default ({ strapi }: { strapi: Strapi }) => ({
|
|
||||||
index(ctx) {
|
|
||||||
ctx.body = strapi
|
|
||||||
.plugin('vendors')
|
|
||||||
.service('myService')
|
|
||||||
.getWelcomeMessage();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
import {Strapi} from '@strapi/strapi';
|
||||||
|
import {string} from "prop-types";
|
||||||
|
|
||||||
|
export default ({strapi}: { strapi: Strapi }) => ({
|
||||||
|
index(ctx) {
|
||||||
|
ctx.body = strapi
|
||||||
|
.plugin('vendors')
|
||||||
|
.service('vendors')
|
||||||
|
.getWelcomeMessage();
|
||||||
|
},
|
||||||
|
async list(ctx) {
|
||||||
|
const user = ctx.state.user;
|
||||||
|
strapi.log.debug(JSON.stringify(user));
|
||||||
|
const vendor = await strapi.plugin('vendors')
|
||||||
|
.service('vendors')
|
||||||
|
.get(user.roles.code);
|
||||||
|
|
||||||
|
if (!vendor) {
|
||||||
|
strapi.log.error('No vendor found');
|
||||||
|
}
|
||||||
|
|
||||||
|
strapi.log.debug(JSON.stringify(vendor));
|
||||||
|
|
||||||
|
ctx.body = await strapi.plugin('vendors')
|
||||||
|
.service('products')
|
||||||
|
.list(vendor.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -1,5 +1,7 @@
|
|||||||
import myService from './my-service';
|
import products from './products';
|
||||||
|
import vendors from './vendors';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
myService,
|
products,
|
||||||
|
vendors
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
import { Strapi } from '@strapi/strapi';
|
|
||||||
|
|
||||||
export default ({ strapi }: { strapi: Strapi }) => ({
|
|
||||||
getWelcomeMessage() {
|
|
||||||
return 'Welcome to Strapi 🚀';
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
import {Strapi} from '@strapi/strapi';
|
||||||
|
|
||||||
|
export default ({strapi}: { strapi: Strapi }) => ({
|
||||||
|
getWelcomeMessage() {
|
||||||
|
return 'Welcome to Strapi 🚀';
|
||||||
|
},
|
||||||
|
async list(vendorId: string) {
|
||||||
|
console.log(vendorId);
|
||||||
|
return await strapi.query('api::product.product').findMany({
|
||||||
|
where: {
|
||||||
|
vendors: {
|
||||||
|
id: vendorId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
import {Strapi} from '@strapi/strapi';
|
||||||
|
|
||||||
|
export default ({strapi}: { strapi: Strapi }) => ({
|
||||||
|
getWelcomeMessage() {
|
||||||
|
return 'Welcome to Strapi 🚀';
|
||||||
|
},
|
||||||
|
async get(roleName: string) {
|
||||||
|
return await strapi.query('api::vendor.vendor').findOne({
|
||||||
|
where: {
|
||||||
|
slug: roleName
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue