mirror of
https://github.com/umami-software/umami.git
synced 2026-02-17 02:55:38 +01:00
Refactored forms and pages.
This commit is contained in:
parent
1325abe31d
commit
6253d55790
57 changed files with 209 additions and 208 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { Button, Icon, Icons, Modal, ModalTrigger, Text, useToasts } from 'react-basics';
|
||||
import WebsiteAddForm from './WebsiteAddForm';
|
||||
import useMessages from 'components/hooks/useMessages';
|
||||
import { setValue } from 'store/cache';
|
||||
|
||||
export function WebsiteAddButton({ onSave }) {
|
||||
const { formatMessage, labels, messages } = useMessages();
|
||||
|
|
@ -8,6 +9,7 @@ export function WebsiteAddButton({ onSave }) {
|
|||
|
||||
const handleSave = async () => {
|
||||
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
||||
setValue('websites', Date.now());
|
||||
onSave?.();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,13 +4,15 @@ import useUser from 'components/hooks/useUser';
|
|||
import useApi from 'components/hooks/useApi';
|
||||
import DataTable from 'components/common/DataTable';
|
||||
import useFilterQuery from 'components/hooks/useFilterQuery';
|
||||
import WebsitesHeader from './WebsitesHeader';
|
||||
import useCache from 'store/cache';
|
||||
|
||||
function useWebsites({ includeTeams, onlyTeams }) {
|
||||
const { user } = useUser();
|
||||
const { get } = useApi();
|
||||
const modified = useCache(state => state?.websites);
|
||||
|
||||
return useFilterQuery(
|
||||
['websites', { includeTeams, onlyTeams }],
|
||||
['websites', { includeTeams, onlyTeams, modified }],
|
||||
params => {
|
||||
return get(`/users/${user?.id}/websites`, {
|
||||
includeTeams,
|
||||
|
|
@ -23,9 +25,8 @@ function useWebsites({ includeTeams, onlyTeams }) {
|
|||
}
|
||||
|
||||
export function WebsitesDataTable({
|
||||
showHeader = true,
|
||||
showEditButton = true,
|
||||
showViewButton = true,
|
||||
allowEdit = true,
|
||||
allowView = true,
|
||||
showActions = true,
|
||||
showTeam,
|
||||
includeTeams,
|
||||
|
|
@ -35,22 +36,19 @@ export function WebsitesDataTable({
|
|||
const queryResult = useWebsites({ includeTeams, onlyTeams });
|
||||
|
||||
return (
|
||||
<>
|
||||
{showHeader && <WebsitesHeader />}
|
||||
<DataTable queryResult={queryResult}>
|
||||
{({ data }) => (
|
||||
<WebsitesTable
|
||||
data={data}
|
||||
showTeam={showTeam}
|
||||
showActions={showActions}
|
||||
showEditButton={showEditButton}
|
||||
showViewButton={showViewButton}
|
||||
>
|
||||
{children}
|
||||
</WebsitesTable>
|
||||
)}
|
||||
</DataTable>
|
||||
</>
|
||||
<DataTable queryResult={queryResult}>
|
||||
{({ data }) => (
|
||||
<WebsitesTable
|
||||
data={data}
|
||||
showTeam={showTeam}
|
||||
showActions={showActions}
|
||||
allowEdit={allowEdit}
|
||||
allowView={allowView}
|
||||
>
|
||||
{children}
|
||||
</WebsitesTable>
|
||||
)}
|
||||
</DataTable>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ export function WebsitesTable({
|
|||
data = [],
|
||||
showTeam,
|
||||
showActions,
|
||||
showEditButton,
|
||||
showViewButton,
|
||||
allowEdit,
|
||||
allowView,
|
||||
children,
|
||||
}) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
|
|
@ -37,7 +37,7 @@ export function WebsitesTable({
|
|||
|
||||
return (
|
||||
<>
|
||||
{showActions && showEditButton && (!showTeam || ownerId === user.id) && (
|
||||
{showActions && allowEdit && (!showTeam || ownerId === user.id) && (
|
||||
<Link href={`/settings/websites/${id}`}>
|
||||
<Button>
|
||||
<Icon>
|
||||
|
|
@ -47,7 +47,7 @@ export function WebsitesTable({
|
|||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
{showActions && showViewButton && (
|
||||
{showActions && allowView && (
|
||||
<Link href={`/websites/${id}`}>
|
||||
<Button>
|
||||
<Icon>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,15 @@
|
|||
import WebsitesDataTable from './WebsitesDataTable';
|
||||
import WebsitesHeader from './WebsitesHeader';
|
||||
|
||||
export default function () {
|
||||
if (process.env.cloudMode) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <WebsitesDataTable />;
|
||||
return (
|
||||
<>
|
||||
<WebsitesHeader />
|
||||
<WebsitesDataTable />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue