mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Updated query hooks for teams and websites.
This commit is contained in:
parent
9448aa3ab5
commit
2fa50892d8
@ -3,13 +3,25 @@ require('dotenv').config();
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const pkg = require('./package.json');
|
const pkg = require('./package.json');
|
||||||
|
|
||||||
|
const basePath = process.env.BASE_PATH || '';
|
||||||
|
const forceSSL = process.env.FORCE_SSL || '';
|
||||||
|
const collectApiEndpoint = process.env.COLLECT_API_ENDPOINT || '';
|
||||||
|
const defaultLocale = process.env.DEFAULT_LOCALE || '';
|
||||||
|
const trackerScriptName = process.env.TRACKER_SCRIPT_NAME || '';
|
||||||
|
const cloudMode = process.env.CLOUD_MODE || '';
|
||||||
|
const cloudUrl = process.env.CLOUD_URL || '';
|
||||||
|
const frameAncestors = process.env.ALLOWED_FRAME_URLS || '';
|
||||||
|
const disableLogin = process.env.DISABLE_LOGIN || '';
|
||||||
|
const disableUI = process.env.DISABLE_UI || '';
|
||||||
|
const hostURL = process.env.HOST_URL || '';
|
||||||
|
|
||||||
const contentSecurityPolicy = [
|
const contentSecurityPolicy = [
|
||||||
`default-src 'self'`,
|
`default-src 'self'`,
|
||||||
`img-src *`,
|
`img-src *`,
|
||||||
`script-src 'self' 'unsafe-eval' 'unsafe-inline'`,
|
`script-src 'self' 'unsafe-eval' 'unsafe-inline'`,
|
||||||
`style-src 'self' 'unsafe-inline'`,
|
`style-src 'self' 'unsafe-inline'`,
|
||||||
`connect-src 'self' api.umami.is cloud.umami.is`,
|
`connect-src 'self' api.umami.is cloud.umami.is`,
|
||||||
`frame-ancestors 'self' ${process.env.ALLOWED_FRAME_URLS || ''}`,
|
`frame-ancestors 'self' ${frameAncestors}`,
|
||||||
];
|
];
|
||||||
|
|
||||||
const headers = [
|
const headers = [
|
||||||
@ -26,7 +38,7 @@ const headers = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
if (process.env.FORCE_SSL) {
|
if (forceSSL) {
|
||||||
headers.push({
|
headers.push({
|
||||||
key: 'Strict-Transport-Security',
|
key: 'Strict-Transport-Security',
|
||||||
value: 'max-age=63072000; includeSubDomains; preload',
|
value: 'max-age=63072000; includeSubDomains; preload',
|
||||||
@ -35,15 +47,15 @@ if (process.env.FORCE_SSL) {
|
|||||||
|
|
||||||
const rewrites = [];
|
const rewrites = [];
|
||||||
|
|
||||||
if (process.env.COLLECT_API_ENDPOINT) {
|
if (collectApiEndpoint) {
|
||||||
rewrites.push({
|
rewrites.push({
|
||||||
source: process.env.COLLECT_API_ENDPOINT,
|
source: collectApiEndpoint,
|
||||||
destination: '/api/send',
|
destination: '/api/send',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.TRACKER_SCRIPT_NAME) {
|
if (trackerScriptName) {
|
||||||
const names = process.env.TRACKER_SCRIPT_NAME?.split(',').map(name => name.trim());
|
const names = trackerScriptName?.split(',').map(name => name.trim());
|
||||||
|
|
||||||
if (names) {
|
if (names) {
|
||||||
names.forEach(name => {
|
names.forEach(name => {
|
||||||
@ -58,36 +70,37 @@ if (process.env.TRACKER_SCRIPT_NAME) {
|
|||||||
const redirects = [
|
const redirects = [
|
||||||
{
|
{
|
||||||
source: '/settings',
|
source: '/settings',
|
||||||
destination: process.env.CLOUD_MODE
|
destination: cloudMode ? `${cloudUrl}/settings/websites` : '/settings/websites',
|
||||||
? `${process.env.CLOUD_URL}/settings/websites`
|
permanent: true,
|
||||||
: '/settings/websites',
|
},
|
||||||
|
{
|
||||||
|
source: '/teams/:id',
|
||||||
|
destination: '/teams/:id/websites',
|
||||||
permanent: true,
|
permanent: true,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
if (process.env.CLOUD_MODE && process.env.CLOUD_URL && process.env.DISABLE_LOGIN) {
|
if (cloudMode && cloudUrl && disableLogin) {
|
||||||
redirects.push({
|
redirects.push({
|
||||||
source: '/login',
|
source: '/login',
|
||||||
destination: process.env.CLOUD_URL,
|
destination: cloudUrl,
|
||||||
permanent: false,
|
permanent: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const basePath = process.env.BASE_PATH;
|
|
||||||
|
|
||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const config = {
|
const config = {
|
||||||
reactStrictMode: false,
|
reactStrictMode: false,
|
||||||
env: {
|
env: {
|
||||||
basePath: basePath || '',
|
basePath,
|
||||||
cloudMode: process.env.CLOUD_MODE || '',
|
cloudMode,
|
||||||
cloudUrl: process.env.CLOUD_URL || '',
|
cloudUrl,
|
||||||
configUrl: '/config',
|
configUrl: '/config',
|
||||||
currentVersion: pkg.version,
|
currentVersion: pkg.version,
|
||||||
defaultLocale: process.env.DEFAULT_LOCALE || '',
|
defaultLocale,
|
||||||
disableLogin: process.env.DISABLE_LOGIN || '',
|
disableLogin,
|
||||||
disableUI: process.env.DISABLE_UI || '',
|
disableUI,
|
||||||
hostUrl: process.env.HOST_URL || '',
|
hostURL,
|
||||||
},
|
},
|
||||||
basePath,
|
basePath,
|
||||||
output: 'standalone',
|
output: 'standalone',
|
||||||
|
@ -3,20 +3,17 @@ import { Button, Icon, Icons, Loading, Text } from 'react-basics';
|
|||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import PageHeader from 'components/layout/PageHeader';
|
import PageHeader from 'components/layout/PageHeader';
|
||||||
import Pager from 'components/common/Pager';
|
import Pager from 'components/common/Pager';
|
||||||
import WebsiteChartList from '../../(main)/websites/[id]/WebsiteChartList';
|
import WebsiteChartList from 'app/(main)/websites/[id]/WebsiteChartList';
|
||||||
import DashboardSettingsButton from 'app/(main)/dashboard/DashboardSettingsButton';
|
import DashboardSettingsButton from 'app/(main)/dashboard/DashboardSettingsButton';
|
||||||
import DashboardEdit from 'app/(main)/dashboard/DashboardEdit';
|
import DashboardEdit from 'app/(main)/dashboard/DashboardEdit';
|
||||||
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
|
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
|
||||||
import { useApi } from 'components/hooks';
|
import { useApi } from 'components/hooks';
|
||||||
import useDashboard from 'store/dashboard';
|
import useDashboard from 'store/dashboard';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages, useLocale, useLogin, useFilterQuery } from 'components/hooks';
|
||||||
import { useLocale } from 'components/hooks';
|
|
||||||
import { useFilterQuery } from 'components/hooks';
|
|
||||||
import { useUser } from 'components/hooks';
|
|
||||||
|
|
||||||
export function Dashboard() {
|
export function Dashboard() {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { user } = useUser();
|
const { user } = useLogin();
|
||||||
const { showCharts, editing } = useDashboard();
|
const { showCharts, editing } = useDashboard();
|
||||||
const { dir } = useLocale();
|
const { dir } = useLocale();
|
||||||
const { get } = useApi();
|
const { get } = useApi();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Button, Icon, Icons, Modal, ModalTrigger, Text } from 'react-basics';
|
import { Button, Icon, Icons, Modal, ModalTrigger, Text } from 'react-basics';
|
||||||
import ConfirmDeleteForm from 'components/common/ConfirmDeleteForm';
|
|
||||||
import { useApi, useMessages } from 'components/hooks';
|
import { useApi, useMessages } from 'components/hooks';
|
||||||
import { setValue } from 'store/cache';
|
import { touch } from 'store/cache';
|
||||||
|
import ConfirmationForm from 'components/common/ConfirmationForm';
|
||||||
|
|
||||||
export function ReportDeleteButton({
|
export function ReportDeleteButton({
|
||||||
reportId,
|
reportId,
|
||||||
@ -12,14 +12,16 @@ export function ReportDeleteButton({
|
|||||||
reportName: string;
|
reportName: string;
|
||||||
onDelete?: () => void;
|
onDelete?: () => void;
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
|
||||||
const { del, useMutation } = useApi();
|
const { del, useMutation } = useApi();
|
||||||
const { mutate } = useMutation({ mutationFn: reportId => del(`/reports/${reportId}`) });
|
const { mutate, isPending, error } = useMutation({
|
||||||
|
mutationFn: reportId => del(`/reports/${reportId}`),
|
||||||
|
});
|
||||||
|
|
||||||
const handleConfirm = (close: () => void) => {
|
const handleConfirm = (close: () => void) => {
|
||||||
mutate(reportId as any, {
|
mutate(reportId as any, {
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
setValue('reports', Date.now());
|
touch('reports');
|
||||||
onDelete?.();
|
onDelete?.();
|
||||||
close();
|
close();
|
||||||
},
|
},
|
||||||
@ -28,16 +30,23 @@ export function ReportDeleteButton({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ModalTrigger>
|
<ModalTrigger>
|
||||||
<Button>
|
<Button variant="quiet">
|
||||||
<Icon>
|
<Icon>
|
||||||
<Icons.Trash />
|
<Icons.Trash />
|
||||||
</Icon>
|
</Icon>
|
||||||
<Text>{formatMessage(labels.delete)}</Text>
|
<Text>{formatMessage(labels.delete)}</Text>
|
||||||
</Button>
|
</Button>
|
||||||
<Modal>
|
<Modal title={formatMessage(labels.deleteReport)}>
|
||||||
{close => (
|
{(close: () => void) => (
|
||||||
<ConfirmDeleteForm
|
<ConfirmationForm
|
||||||
name={reportName}
|
message={
|
||||||
|
<FormattedMessage
|
||||||
|
{...messages.confirmDelete}
|
||||||
|
values={{ target: <b>{reportName}</b> }}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
isLoading={isPending}
|
||||||
|
error={error}
|
||||||
onConfirm={handleConfirm.bind(null, close)}
|
onConfirm={handleConfirm.bind(null, close)}
|
||||||
onClose={close}
|
onClose={close}
|
||||||
/>
|
/>
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
import { GridColumn, GridTable, Icon, Icons, Text, useBreakpoint } from 'react-basics';
|
import { GridColumn, GridTable, Icon, Icons, Text, useBreakpoint } from 'react-basics';
|
||||||
import LinkButton from 'components/common/LinkButton';
|
import LinkButton from 'components/common/LinkButton';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages, useLogin } from 'components/hooks';
|
||||||
import { useUser } from 'components/hooks';
|
|
||||||
import { REPORT_TYPES } from 'lib/constants';
|
import { REPORT_TYPES } from 'lib/constants';
|
||||||
import ReportDeleteButton from './ReportDeleteButton';
|
import ReportDeleteButton from './ReportDeleteButton';
|
||||||
|
|
||||||
export function ReportsTable({ data = [], showDomain }: { data: any[]; showDomain?: boolean }) {
|
export function ReportsTable({ data = [], showDomain }: { data: any[]; showDomain?: boolean }) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { user } = useUser();
|
const { user } = useLogin();
|
||||||
const breakpoint = useBreakpoint();
|
const breakpoint = useBreakpoint();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { JSX, useCallback, useContext, useMemo } from 'react';
|
import { JSX, useCallback, useContext, useMemo } from 'react';
|
||||||
import { Loading, StatusLight } from 'react-basics';
|
import { Loading, StatusLight } from 'react-basics';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages, useTheme } from 'components/hooks';
|
||||||
import { useTheme } from 'components/hooks';
|
|
||||||
import BarChart from 'components/metrics/BarChart';
|
import BarChart from 'components/metrics/BarChart';
|
||||||
import { formatLongNumber } from 'lib/format';
|
import { formatLongNumber } from 'lib/format';
|
||||||
import { ReportContext } from '../[id]/Report';
|
import { ReportContext } from '../[id]/Report';
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import { usePathname } from 'next/navigation';
|
import { usePathname } from 'next/navigation';
|
||||||
import { useUser } from 'components/hooks';
|
import { useLogin, useMessages } from 'components/hooks';
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
import SideNav from 'components/layout/SideNav';
|
import SideNav from 'components/layout/SideNav';
|
||||||
import styles from './layout.module.css';
|
import styles from './layout.module.css';
|
||||||
|
|
||||||
export default function SettingsLayout({ children }) {
|
export default function SettingsLayout({ children }) {
|
||||||
const { user } = useUser();
|
const { user } = useLogin();
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const cloudMode = !!process.env.cloudMode;
|
const cloudMode = !!process.env.cloudMode;
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import DateFilter from 'components/input/DateFilter';
|
import DateFilter from 'components/input/DateFilter';
|
||||||
import { Button, Flexbox } from 'react-basics';
|
import { Button, Flexbox } from 'react-basics';
|
||||||
import { useDateRange } from 'components/hooks';
|
import { useDateRange, useMessages } from 'components/hooks';
|
||||||
import { DEFAULT_DATE_RANGE } from 'lib/constants';
|
import { DEFAULT_DATE_RANGE } from 'lib/constants';
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
import { DateRange } from 'lib/types';
|
import { DateRange } from 'lib/types';
|
||||||
|
|
||||||
export function DateRangeSetting() {
|
export function DateRangeSetting() {
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Button, Dropdown, Item, Flexbox } from 'react-basics';
|
import { Button, Dropdown, Item, Flexbox } from 'react-basics';
|
||||||
import { useLocale } from 'components/hooks';
|
import { useLocale, useMessages } from 'components/hooks';
|
||||||
import { DEFAULT_LOCALE } from 'lib/constants';
|
import { DEFAULT_LOCALE } from 'lib/constants';
|
||||||
import { languages } from 'lib/lang';
|
import { languages } from 'lib/lang';
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
import styles from './LanguageSetting.module.css';
|
import styles from './LanguageSetting.module.css';
|
||||||
|
|
||||||
export function LanguageSetting() {
|
export function LanguageSetting() {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { useRef } from 'react';
|
import { useRef } from 'react';
|
||||||
import { Form, FormRow, FormInput, FormButtons, PasswordField, Button } from 'react-basics';
|
import { Form, FormRow, FormInput, FormButtons, PasswordField, Button } from 'react-basics';
|
||||||
import { useApi } from 'components/hooks';
|
import { useApi, useMessages } from 'components/hooks';
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
|
|
||||||
export function PasswordEditForm({ onSave, onClose }) {
|
export function PasswordEditForm({ onSave, onClose }) {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
|
@ -5,12 +5,11 @@ import DateRangeSetting from 'app/(main)/settings/profile/DateRangeSetting';
|
|||||||
import LanguageSetting from 'app/(main)/settings/profile/LanguageSetting';
|
import LanguageSetting from 'app/(main)/settings/profile/LanguageSetting';
|
||||||
import ThemeSetting from 'app/(main)/settings/profile/ThemeSetting';
|
import ThemeSetting from 'app/(main)/settings/profile/ThemeSetting';
|
||||||
import PasswordChangeButton from './PasswordChangeButton';
|
import PasswordChangeButton from './PasswordChangeButton';
|
||||||
import { useUser } from 'components/hooks';
|
import { useLogin, useMessages } from 'components/hooks';
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
import { ROLES } from 'lib/constants';
|
import { ROLES } from 'lib/constants';
|
||||||
|
|
||||||
export function ProfileSettings() {
|
export function ProfileSettings() {
|
||||||
const { user } = useUser();
|
const { user } = useLogin();
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const cloudMode = Boolean(process.env.cloudMode);
|
const cloudMode = Boolean(process.env.cloudMode);
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Dropdown, Item, Button, Flexbox } from 'react-basics';
|
import { Dropdown, Item, Button, Flexbox } from 'react-basics';
|
||||||
import { listTimeZones } from 'timezone-support';
|
import { listTimeZones } from 'timezone-support';
|
||||||
import { useTimezone } from 'components/hooks';
|
import { useTimezone, useMessages } from 'components/hooks';
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
import { getTimezone } from 'lib/date';
|
import { getTimezone } from 'lib/date';
|
||||||
import styles from './TimezoneSetting.module.css';
|
import styles from './TimezoneSetting.module.css';
|
||||||
|
|
||||||
|
@ -8,8 +8,7 @@ import {
|
|||||||
SubmitButton,
|
SubmitButton,
|
||||||
} from 'react-basics';
|
} from 'react-basics';
|
||||||
import { setValue } from 'store/cache';
|
import { setValue } from 'store/cache';
|
||||||
import { useApi } from 'components/hooks';
|
import { useApi, useMessages } from 'components/hooks';
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
|
|
||||||
export function TeamAddForm({ onSave, onClose }: { onSave: () => void; onClose: () => void }) {
|
export function TeamAddForm({ onSave, onClose }: { onSave: () => void; onClose: () => void }) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
|
@ -1,29 +1,28 @@
|
|||||||
import { Button, Form, FormButtons, SubmitButton } from 'react-basics';
|
import { useApi, useMessages } from 'components/hooks';
|
||||||
import { useApi } from 'components/hooks';
|
import { touch } from 'store/cache';
|
||||||
import { useMessages } from 'components/hooks';
|
import TypeConfirmationForm from 'components/common/TypeConfirmationForm';
|
||||||
import { setValue } from 'store/cache';
|
|
||||||
|
const CONFIRM_VALUE = 'DELETE';
|
||||||
|
|
||||||
export function TeamDeleteForm({
|
export function TeamDeleteForm({
|
||||||
teamId,
|
teamId,
|
||||||
teamName,
|
|
||||||
onSave,
|
onSave,
|
||||||
onClose,
|
onClose,
|
||||||
}: {
|
}: {
|
||||||
teamId: string;
|
teamId: string;
|
||||||
teamName: string;
|
onSave?: () => void;
|
||||||
onSave: () => void;
|
onClose?: () => void;
|
||||||
onClose: () => void;
|
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
|
const { labels, formatMessage } = useMessages();
|
||||||
const { del, useMutation } = useApi();
|
const { del, useMutation } = useApi();
|
||||||
const { mutate, error, isPending } = useMutation({
|
const { mutate, error, isPending } = useMutation({
|
||||||
mutationFn: (data: any) => del(`/teams/${teamId}`, data),
|
mutationFn: (data: any) => del(`/teams/${teamId}`, data),
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmit = async data => {
|
const handleConfirm = async () => {
|
||||||
mutate(data, {
|
mutate(null, {
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
setValue('teams', Date.now());
|
touch('teams');
|
||||||
onSave?.();
|
onSave?.();
|
||||||
onClose?.();
|
onClose?.();
|
||||||
},
|
},
|
||||||
@ -31,17 +30,15 @@ export function TeamDeleteForm({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form onSubmit={handleSubmit} error={error}>
|
<TypeConfirmationForm
|
||||||
<p>
|
confirmationValue={CONFIRM_VALUE}
|
||||||
<FormattedMessage {...messages.confirmDelete} values={{ target: <b>{teamName}</b> }} />
|
onConfirm={handleConfirm}
|
||||||
</p>
|
onClose={onClose}
|
||||||
<FormButtons flex>
|
isLoading={isPending}
|
||||||
<SubmitButton variant="danger" disabled={isPending}>
|
error={error}
|
||||||
{formatMessage(labels.delete)}
|
buttonLabel={formatMessage(labels.delete)}
|
||||||
</SubmitButton>
|
buttonVariant="danger"
|
||||||
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
|
/>
|
||||||
</FormButtons>
|
|
||||||
</Form>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,8 +8,7 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
SubmitButton,
|
SubmitButton,
|
||||||
} from 'react-basics';
|
} from 'react-basics';
|
||||||
import { useApi } from 'components/hooks';
|
import { useApi, useMessages } from 'components/hooks';
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
import { setValue } from 'store/cache';
|
import { setValue } from 'store/cache';
|
||||||
|
|
||||||
export function TeamJoinForm({ onSave, onClose }: { onSave: () => void; onClose: () => void }) {
|
export function TeamJoinForm({ onSave, onClose }: { onSave: () => void; onClose: () => void }) {
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import { Button, Icon, Icons, Modal, ModalTrigger, Text } from 'react-basics';
|
import { Button, Icon, Icons, Modal, ModalTrigger, Text } from 'react-basics';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages, useLocale, useLogin } from 'components/hooks';
|
||||||
import { useLocale } from 'components/hooks';
|
|
||||||
import { useUser } from 'components/hooks';
|
|
||||||
import TeamDeleteForm from './TeamLeaveForm';
|
import TeamDeleteForm from './TeamLeaveForm';
|
||||||
|
|
||||||
export function TeamLeaveButton({
|
export function TeamLeaveButton({
|
||||||
@ -15,7 +13,7 @@ export function TeamLeaveButton({
|
|||||||
}) {
|
}) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { dir } = useLocale();
|
const { dir } = useLocale();
|
||||||
const { user } = useUser();
|
const { user } = useLogin();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ModalTrigger>
|
<ModalTrigger>
|
||||||
@ -26,7 +24,7 @@ export function TeamLeaveButton({
|
|||||||
<Text>{formatMessage(labels.leave)}</Text>
|
<Text>{formatMessage(labels.leave)}</Text>
|
||||||
</Button>
|
</Button>
|
||||||
<Modal title={formatMessage(labels.leaveTeam)}>
|
<Modal title={formatMessage(labels.leaveTeam)}>
|
||||||
{close => (
|
{(close: () => void) => (
|
||||||
<TeamDeleteForm
|
<TeamDeleteForm
|
||||||
teamId={teamId}
|
teamId={teamId}
|
||||||
userId={user.id}
|
userId={user.id}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { Button, Form, FormButtons, SubmitButton } from 'react-basics';
|
import { useApi, useMessages } from 'components/hooks';
|
||||||
import { useApi } from 'components/hooks';
|
import { touch } from 'store/cache';
|
||||||
import { useMessages } from 'components/hooks';
|
import ConfirmationForm from 'components/common/ConfirmationForm';
|
||||||
import { setValue } from 'store/cache';
|
|
||||||
|
|
||||||
export function TeamLeaveForm({
|
export function TeamLeaveForm({
|
||||||
teamId,
|
teamId,
|
||||||
@ -22,10 +21,10 @@ export function TeamLeaveForm({
|
|||||||
mutationFn: () => del(`/teams/${teamId}/users/${userId}`),
|
mutationFn: () => del(`/teams/${teamId}/users/${userId}`),
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleConfirm = async () => {
|
||||||
mutate(null, {
|
mutate(null, {
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
setValue('team:members', Date.now());
|
touch('team:members');
|
||||||
onSave();
|
onSave();
|
||||||
onClose();
|
onClose();
|
||||||
},
|
},
|
||||||
@ -33,17 +32,16 @@ export function TeamLeaveForm({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form onSubmit={handleSubmit} error={error}>
|
<ConfirmationForm
|
||||||
<p>
|
buttonLabel={formatMessage(labels.leave)}
|
||||||
|
message={
|
||||||
<FormattedMessage {...messages.confirmDelete} values={{ target: <b>{teamName}</b> }} />
|
<FormattedMessage {...messages.confirmDelete} values={{ target: <b>{teamName}</b> }} />
|
||||||
</p>
|
}
|
||||||
<FormButtons flex>
|
onConfirm={handleConfirm}
|
||||||
<SubmitButton variant="danger" disabled={isPending}>
|
onClose={onClose}
|
||||||
{formatMessage(labels.leave)}
|
isLoading={isPending}
|
||||||
</SubmitButton>
|
error={error}
|
||||||
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
|
/>
|
||||||
</FormButtons>
|
|
||||||
</Form>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import DataTable from 'components/common/DataTable';
|
import DataTable from 'components/common/DataTable';
|
||||||
import TeamsTable from 'app/(main)/settings/teams/TeamsTable';
|
import TeamsTable from 'app/(main)/settings/teams/TeamsTable';
|
||||||
import { useApi } from 'components/hooks';
|
import { useApi, useFilterQuery } from 'components/hooks';
|
||||||
import { useFilterQuery } from 'components/hooks';
|
|
||||||
import useCache from 'store/cache';
|
import useCache from 'store/cache';
|
||||||
|
|
||||||
export function TeamsDataTable() {
|
export function TeamsDataTable() {
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
import { Flexbox } from 'react-basics';
|
import { Flexbox } from 'react-basics';
|
||||||
import PageHeader from 'components/layout/PageHeader';
|
import PageHeader from 'components/layout/PageHeader';
|
||||||
import { ROLES } from 'lib/constants';
|
import { ROLES } from 'lib/constants';
|
||||||
import { useUser } from 'components/hooks';
|
import { useLogin, useMessages } from 'components/hooks';
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
import TeamsJoinButton from './TeamsJoinButton';
|
import TeamsJoinButton from './TeamsJoinButton';
|
||||||
import TeamsAddButton from './TeamsAddButton';
|
import TeamsAddButton from './TeamsAddButton';
|
||||||
|
|
||||||
export function TeamsHeader({ allowCreate = true }: { allowCreate?: boolean }) {
|
export function TeamsHeader({ allowCreate = true }: { allowCreate?: boolean }) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { user } = useUser();
|
const { user } = useLogin();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageHeader title={formatMessage(labels.teams)}>
|
<PageHeader title={formatMessage(labels.teams)}>
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import { Button, GridColumn, GridTable, Icon, Icons, Text, useBreakpoint } from 'react-basics';
|
import { Button, GridColumn, GridTable, Icon, Icons, Text, useBreakpoint } from 'react-basics';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages, useLogin } from 'components/hooks';
|
||||||
import { useUser } from 'components/hooks';
|
|
||||||
import { ROLES } from 'lib/constants';
|
import { ROLES } from 'lib/constants';
|
||||||
|
|
||||||
export function TeamsTable({ data = [] }: { data: any[] }) {
|
export function TeamsTable({ data = [] }: { data: any[] }) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { user } = useUser();
|
const { user } = useLogin();
|
||||||
const breakpoint = useBreakpoint();
|
const breakpoint = useBreakpoint();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -2,11 +2,9 @@ import { ActionForm, Button, Modal, ModalTrigger } from 'react-basics';
|
|||||||
import { useMessages } from 'components/hooks';
|
import { useMessages } from 'components/hooks';
|
||||||
import TeamDeleteForm from '../TeamDeleteForm';
|
import TeamDeleteForm from '../TeamDeleteForm';
|
||||||
|
|
||||||
export function TeamData({ teamId }: { teamId: string; onSave?: (value: string) => void }) {
|
export function TeamData({ teamId }: { teamId: string }) {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
|
|
||||||
const handleSave = () => {};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ActionForm
|
<ActionForm
|
||||||
label={formatMessage(labels.deleteTeam)}
|
label={formatMessage(labels.deleteTeam)}
|
||||||
@ -15,9 +13,7 @@ export function TeamData({ teamId }: { teamId: string; onSave?: (value: string)
|
|||||||
<ModalTrigger>
|
<ModalTrigger>
|
||||||
<Button variant="danger">{formatMessage(labels.delete)}</Button>
|
<Button variant="danger">{formatMessage(labels.delete)}</Button>
|
||||||
<Modal title={formatMessage(labels.deleteTeam)}>
|
<Modal title={formatMessage(labels.deleteTeam)}>
|
||||||
{(close: () => void) => (
|
{(close: () => void) => <TeamDeleteForm teamId={teamId} onClose={close} />}
|
||||||
<TeamDeleteForm teamId={teamId} teamName={''} onSave={handleSave} onClose={close} />
|
|
||||||
)}
|
|
||||||
</Modal>
|
</Modal>
|
||||||
</ModalTrigger>
|
</ModalTrigger>
|
||||||
</ActionForm>
|
</ActionForm>
|
||||||
|
@ -7,28 +7,37 @@ import {
|
|||||||
TextField,
|
TextField,
|
||||||
Button,
|
Button,
|
||||||
Flexbox,
|
Flexbox,
|
||||||
|
useToasts,
|
||||||
} from 'react-basics';
|
} from 'react-basics';
|
||||||
import { getRandomChars } from 'next-basics';
|
import { getRandomChars } from 'next-basics';
|
||||||
import { useRef, useState } from 'react';
|
import { useRef, useState } from 'react';
|
||||||
import { useApi } from 'components/hooks';
|
import { useApi, useMessages } from 'components/hooks';
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
|
|
||||||
const generateId = () => getRandomChars(16);
|
const generateId = () => getRandomChars(16);
|
||||||
|
|
||||||
export function TeamEditForm({ teamId, data, onSave, readOnly }) {
|
export function TeamEditForm({
|
||||||
const { formatMessage, labels } = useMessages();
|
teamId,
|
||||||
|
data,
|
||||||
|
readOnly,
|
||||||
|
}: {
|
||||||
|
teamId: string;
|
||||||
|
data?: { name: string; accessCode: string };
|
||||||
|
readOnly?: boolean;
|
||||||
|
}) {
|
||||||
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
const { mutate, error } = useMutation({
|
const { mutate, error } = useMutation({
|
||||||
mutationFn: (data: any) => post(`/teams/${teamId}`, data),
|
mutationFn: (data: any) => post(`/teams/${teamId}`, data),
|
||||||
});
|
});
|
||||||
const ref = useRef(null);
|
const ref = useRef(null);
|
||||||
const [accessCode, setAccessCode] = useState(data.accessCode);
|
const [accessCode, setAccessCode] = useState(data.accessCode);
|
||||||
|
const { showToast } = useToasts();
|
||||||
|
|
||||||
const handleSubmit = async (data: any) => {
|
const handleSubmit = async (data: any) => {
|
||||||
mutate(data, {
|
mutate(data, {
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
ref.current.reset(data);
|
ref.current.reset(data);
|
||||||
onSave?.(data);
|
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { useApi } from 'components/hooks';
|
import { useApi, useMessages } from 'components/hooks';
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
import { Icon, Icons, LoadingButton, Text } from 'react-basics';
|
import { Icon, Icons, LoadingButton, Text } from 'react-basics';
|
||||||
import { setValue } from 'store/cache';
|
import { setValue } from 'store/cache';
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { useApi } from 'components/hooks';
|
import { useApi, useFilterQuery } from 'components/hooks';
|
||||||
import { useFilterQuery } from 'components/hooks';
|
|
||||||
import DataTable from 'components/common/DataTable';
|
import DataTable from 'components/common/DataTable';
|
||||||
import useCache from 'store/cache';
|
import useCache from 'store/cache';
|
||||||
import TeamMembersTable from './TeamMembersTable';
|
import TeamMembersTable from './TeamMembersTable';
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { GridColumn, GridTable, useBreakpoint } from 'react-basics';
|
import { GridColumn, GridTable, useBreakpoint } from 'react-basics';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages, useLogin } from 'components/hooks';
|
||||||
import { useUser } from 'components/hooks';
|
|
||||||
import { ROLES } from 'lib/constants';
|
import { ROLES } from 'lib/constants';
|
||||||
import TeamMemberRemoveButton from './TeamMemberRemoveButton';
|
import TeamMemberRemoveButton from './TeamMemberRemoveButton';
|
||||||
|
|
||||||
@ -14,7 +13,7 @@ export function TeamMembersTable({
|
|||||||
readOnly: boolean;
|
readOnly: boolean;
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { user } = useUser();
|
const { user } = useLogin();
|
||||||
const breakpoint = useBreakpoint();
|
const breakpoint = useBreakpoint();
|
||||||
|
|
||||||
const roles = {
|
const roles = {
|
||||||
|
@ -1,66 +1,49 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import { useEffect, useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Item, Loading, Tabs, useToasts, Flexbox } from 'react-basics';
|
import { Item, Loading, Tabs, Flexbox } from 'react-basics';
|
||||||
|
import TeamsContext from 'app/(main)/teams/TeamsContext';
|
||||||
import PageHeader from 'components/layout/PageHeader';
|
import PageHeader from 'components/layout/PageHeader';
|
||||||
import { ROLES } from 'lib/constants';
|
import { ROLES } from 'lib/constants';
|
||||||
import { useUser } from 'components/hooks';
|
import { useLogin, useTeam, useMessages } from 'components/hooks';
|
||||||
import { useApi } from 'components/hooks';
|
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
import TeamEditForm from './TeamEditForm';
|
import TeamEditForm from './TeamEditForm';
|
||||||
import TeamMembers from './TeamMembers';
|
import TeamMembers from './TeamMembers';
|
||||||
import TeamWebsites from './TeamWebsites';
|
import TeamWebsites from './TeamWebsites';
|
||||||
import TeamData from './TeamData';
|
import TeamData from './TeamData';
|
||||||
|
|
||||||
export function TeamSettings({ teamId }: { teamId: string }) {
|
export function TeamSettings({ teamId }: { teamId: string }) {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { user } = useUser();
|
const { user } = useLogin();
|
||||||
const [values, setValues] = useState(null);
|
const { data: team, isLoading } = useTeam(teamId);
|
||||||
const [tab, setTab] = useState('details');
|
const [tab, setTab] = useState('details');
|
||||||
const { get, useQuery } = useApi();
|
|
||||||
const { showToast } = useToasts();
|
if (isLoading) {
|
||||||
const { data, isLoading } = useQuery({
|
return <Loading position="page" />;
|
||||||
queryKey: ['team', teamId],
|
}
|
||||||
queryFn: () => {
|
|
||||||
if (teamId) {
|
const canEdit = team?.teamUser?.find(
|
||||||
return get(`/teams/${teamId}`);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const canEdit = data?.teamUser?.find(
|
|
||||||
({ userId, role }) => role === ROLES.teamOwner && userId === user.id,
|
({ userId, role }) => role === ROLES.teamOwner && userId === user.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSave = data => {
|
|
||||||
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
|
||||||
setValues(state => ({ ...state, ...data }));
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (data) {
|
|
||||||
setValues(data);
|
|
||||||
}
|
|
||||||
}, [data]);
|
|
||||||
|
|
||||||
if (isLoading || !values) {
|
|
||||||
return <Loading />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flexbox direction="column">
|
<TeamsContext.Provider value={team}>
|
||||||
<PageHeader title={values?.name} />
|
<Flexbox direction="column">
|
||||||
<Tabs selectedKey={tab} onSelect={(value: any) => setTab(value)} style={{ marginBottom: 30 }}>
|
<PageHeader title={team?.name} />
|
||||||
<Item key="details">{formatMessage(labels.details)}</Item>
|
<Tabs
|
||||||
<Item key="members">{formatMessage(labels.members)}</Item>
|
selectedKey={tab}
|
||||||
<Item key="websites">{formatMessage(labels.websites)}</Item>
|
onSelect={(value: any) => setTab(value)}
|
||||||
<Item key="data">{formatMessage(labels.data)}</Item>
|
style={{ marginBottom: 30 }}
|
||||||
</Tabs>
|
>
|
||||||
{tab === 'details' && (
|
<Item key="details">{formatMessage(labels.details)}</Item>
|
||||||
<TeamEditForm teamId={teamId} data={values} onSave={handleSave} readOnly={!canEdit} />
|
<Item key="members">{formatMessage(labels.members)}</Item>
|
||||||
)}
|
<Item key="websites">{formatMessage(labels.websites)}</Item>
|
||||||
{tab === 'members' && <TeamMembers teamId={teamId} readOnly={!canEdit} />}
|
<Item key="data">{formatMessage(labels.data)}</Item>
|
||||||
{tab === 'websites' && <TeamWebsites teamId={teamId} readOnly={!canEdit} />}
|
</Tabs>
|
||||||
{canEdit && tab === 'data' && <TeamData teamId={teamId} />}
|
{tab === 'details' && <TeamEditForm teamId={teamId} data={team} readOnly={!canEdit} />}
|
||||||
</Flexbox>
|
{tab === 'members' && <TeamMembers teamId={teamId} readOnly={!canEdit} />}
|
||||||
|
{tab === 'websites' && <TeamWebsites teamId={teamId} readOnly={!canEdit} />}
|
||||||
|
{canEdit && tab === 'data' && <TeamData teamId={teamId} />}
|
||||||
|
</Flexbox>
|
||||||
|
</TeamsContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { useApi } from 'components/hooks';
|
import { useApi, useMessages } from 'components/hooks';
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
import { Icon, Icons, LoadingButton, Text } from 'react-basics';
|
import { Icon, Icons, LoadingButton, Text } from 'react-basics';
|
||||||
|
|
||||||
export function TeamWebsiteRemoveButton({ teamId, websiteId, onSave }) {
|
export function TeamWebsiteRemoveButton({ teamId, websiteId, onSave }) {
|
||||||
|
@ -10,9 +10,8 @@ import {
|
|||||||
SubmitButton,
|
SubmitButton,
|
||||||
Button,
|
Button,
|
||||||
} from 'react-basics';
|
} from 'react-basics';
|
||||||
import { useApi } from 'components/hooks';
|
import { useApi, useMessages } from 'components/hooks';
|
||||||
import { ROLES } from 'lib/constants';
|
import { ROLES } from 'lib/constants';
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
|
|
||||||
export function UserAddForm({ onSave, onClose }) {
|
export function UserAddForm({ onSave, onClose }) {
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { Button, Icon, Icons, Modal, ModalTrigger, Text } from 'react-basics';
|
import { Button, Icon, Icons, Modal, ModalTrigger, Text } from 'react-basics';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages, useLogin } from 'components/hooks';
|
||||||
import { useUser } from 'components/hooks';
|
|
||||||
import UserDeleteForm from './UserDeleteForm';
|
import UserDeleteForm from './UserDeleteForm';
|
||||||
|
|
||||||
export function UserDeleteButton({
|
export function UserDeleteButton({
|
||||||
@ -13,11 +12,11 @@ export function UserDeleteButton({
|
|||||||
onDelete?: () => void;
|
onDelete?: () => void;
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { user } = useUser();
|
const { user } = useLogin();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ModalTrigger disabled={userId === user?.id}>
|
<ModalTrigger disabled={userId === user?.id}>
|
||||||
<Button disabled={userId === user?.id}>
|
<Button disabled={userId === user?.id} variant="quiet">
|
||||||
<Icon>
|
<Icon>
|
||||||
<Icons.Trash />
|
<Icons.Trash />
|
||||||
</Icon>
|
</Icon>
|
||||||
|
@ -1,35 +1,33 @@
|
|||||||
import { Button, Form, FormButtons, SubmitButton } from 'react-basics';
|
import { useApi, useMessages } from 'components/hooks';
|
||||||
import { useApi } from 'components/hooks';
|
import ConfirmationForm from 'components/common/ConfirmationForm';
|
||||||
import { useMessages } from 'components/hooks';
|
import { touch } from 'store/cache';
|
||||||
|
|
||||||
export function UserDeleteForm({ userId, username, onSave, onClose }) {
|
export function UserDeleteForm({ userId, username, onSave, onClose }) {
|
||||||
const { formatMessage, FormattedMessage, labels, messages } = useMessages();
|
const { FormattedMessage, messages, labels, formatMessage } = useMessages();
|
||||||
const { del, useMutation } = useApi();
|
const { del, useMutation } = useApi();
|
||||||
const { mutate, error, isPending } = useMutation({ mutationFn: () => del(`/users/${userId}`) });
|
const { mutate, error, isPending } = useMutation({ mutationFn: () => del(`/users/${userId}`) });
|
||||||
|
|
||||||
const handleSubmit = async (data: any) => {
|
const handleConfirm = async () => {
|
||||||
mutate(data, {
|
mutate(null, {
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
onSave();
|
touch('users');
|
||||||
onClose();
|
onSave?.();
|
||||||
|
onClose?.();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form onSubmit={handleSubmit} error={error}>
|
<ConfirmationForm
|
||||||
<p>
|
message={
|
||||||
<FormattedMessage {...messages.confirmDelete} values={{ target: <b>{username}</b> }} />
|
<FormattedMessage {...messages.confirmDelete} values={{ target: <b>{username}</b> }} />
|
||||||
</p>
|
}
|
||||||
<FormButtons flex>
|
onConfirm={handleConfirm}
|
||||||
<SubmitButton variant="danger" disabled={isPending}>
|
onClose={onClose}
|
||||||
{formatMessage(labels.delete)}
|
buttonLabel={formatMessage(labels.delete)}
|
||||||
</SubmitButton>
|
isLoading={isPending}
|
||||||
<Button disabled={isPending} onClick={onClose}>
|
error={error}
|
||||||
{formatMessage(labels.cancel)}
|
/>
|
||||||
</Button>
|
|
||||||
</FormButtons>
|
|
||||||
</Form>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,9 +9,8 @@ import {
|
|||||||
SubmitButton,
|
SubmitButton,
|
||||||
PasswordField,
|
PasswordField,
|
||||||
} from 'react-basics';
|
} from 'react-basics';
|
||||||
import { useApi } from 'components/hooks';
|
import { useApi, useMessages } from 'components/hooks';
|
||||||
import { ROLES } from 'lib/constants';
|
import { ROLES } from 'lib/constants';
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
|
|
||||||
export function UserEditForm({
|
export function UserEditForm({
|
||||||
userId,
|
userId,
|
||||||
@ -19,8 +18,8 @@ export function UserEditForm({
|
|||||||
onSave,
|
onSave,
|
||||||
}: {
|
}: {
|
||||||
userId: string;
|
userId: string;
|
||||||
data: any[];
|
data: object;
|
||||||
onSave: (data: any) => void;
|
onSave?: (data: any) => void;
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
@ -44,7 +43,7 @@ export function UserEditForm({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderValue = value => {
|
const renderValue = (value: string) => {
|
||||||
if (value === ROLES.user) {
|
if (value === ROLES.user) {
|
||||||
return formatMessage(labels.user);
|
return formatMessage(labels.user);
|
||||||
}
|
}
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
import Page from 'components/layout/Page';
|
|
||||||
import { useApi } from 'components/hooks';
|
|
||||||
import WebsitesTable from 'app/(main)/settings/websites/WebsitesTable';
|
|
||||||
import { useFilterQuery } from 'components/hooks';
|
|
||||||
import DataTable from 'components/common/DataTable';
|
|
||||||
|
|
||||||
export function UserWebsites({ userId }) {
|
|
||||||
const { get } = useApi();
|
|
||||||
const queryResult = useFilterQuery({
|
|
||||||
queryKey: ['user:websites', userId],
|
|
||||||
queryFn: (params: any) => get(`/users/${userId}/websites`, params),
|
|
||||||
});
|
|
||||||
const hasData = queryResult.result && queryResult.result.data.length !== 0;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Page isLoading={queryResult.query.isLoading} error={queryResult.query.error}>
|
|
||||||
{hasData && (
|
|
||||||
<DataTable queryResult={queryResult}>
|
|
||||||
{({ data }) => (
|
|
||||||
<WebsitesTable data={data} showActions={true} allowEdit={true} allowView={true} />
|
|
||||||
)}
|
|
||||||
</DataTable>
|
|
||||||
)}
|
|
||||||
</Page>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default UserWebsites;
|
|
@ -1,17 +1,10 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import { useApi } from 'components/hooks';
|
|
||||||
import { useFilterQuery } from 'components/hooks';
|
|
||||||
import DataTable from 'components/common/DataTable';
|
import DataTable from 'components/common/DataTable';
|
||||||
import UsersTable from './UsersTable';
|
import UsersTable from './UsersTable';
|
||||||
import useCache from 'store/cache';
|
import useUsers from 'components/hooks/queries/useUsers';
|
||||||
|
|
||||||
export function UsersDataTable({ showActions }: { showActions: boolean }) {
|
export function UsersDataTable({ showActions }: { showActions?: boolean }) {
|
||||||
const { get } = useApi();
|
const queryResult = useUsers();
|
||||||
const modified = useCache((state: any) => state?.users);
|
|
||||||
const queryResult = useFilterQuery({
|
|
||||||
queryKey: ['users', { modified }],
|
|
||||||
queryFn: (params: { [key: string]: any }) => get(`/admin/users`, params),
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataTable queryResult={queryResult}>
|
<DataTable queryResult={queryResult}>
|
||||||
|
@ -2,8 +2,7 @@ import { Button, Text, Icon, Icons, GridTable, GridColumn, useBreakpoint } from
|
|||||||
import { formatDistance } from 'date-fns';
|
import { formatDistance } from 'date-fns';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { ROLES } from 'lib/constants';
|
import { ROLES } from 'lib/constants';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages, useLocale } from 'components/hooks';
|
||||||
import { useLocale } from 'components/hooks';
|
|
||||||
import UserDeleteButton from './UserDeleteButton';
|
import UserDeleteButton from './UserDeleteButton';
|
||||||
|
|
||||||
export function UsersTable({
|
export function UsersTable({
|
||||||
@ -35,12 +34,16 @@ export function UsersTable({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
</GridColumn>
|
</GridColumn>
|
||||||
|
<GridColumn name="websites" label={formatMessage(labels.websites)} width={'120px'}>
|
||||||
|
{row => row._count.website}
|
||||||
|
</GridColumn>
|
||||||
{showActions && (
|
{showActions && (
|
||||||
<GridColumn name="action" label=" " alignment="end">
|
<GridColumn name="action" label=" " alignment="end">
|
||||||
{row => {
|
{row => {
|
||||||
const { id, username } = row;
|
const { id, username } = row;
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
<UserDeleteButton userId={id} username={username} />
|
||||||
<Link href={`/settings/users/${id}`}>
|
<Link href={`/settings/users/${id}`}>
|
||||||
<Button>
|
<Button>
|
||||||
<Icon>
|
<Icon>
|
||||||
@ -49,7 +52,6 @@ export function UsersTable({
|
|||||||
<Text>{formatMessage(labels.edit)}</Text>
|
<Text>{formatMessage(labels.edit)}</Text>
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
<UserDeleteButton userId={id} username={username} />
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
|
@ -1,58 +1,28 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import { Key, useEffect, useState } from 'react';
|
import { Key, useState } from 'react';
|
||||||
import { Item, Loading, Tabs, useToasts } from 'react-basics';
|
import { Item, Loading, Tabs } from 'react-basics';
|
||||||
import UserEditForm from '../UserEditForm';
|
import UserEditForm from '../UserEditForm';
|
||||||
import PageHeader from 'components/layout/PageHeader';
|
import PageHeader from 'components/layout/PageHeader';
|
||||||
import { useApi } from 'components/hooks';
|
import { useMessages, useUser } from 'components/hooks';
|
||||||
import { useMessages } from 'components/hooks';
|
import UserWebsites from './UserWebsites';
|
||||||
import UserWebsites from '../UserWebsites';
|
|
||||||
|
|
||||||
export function UserSettings({ userId }) {
|
export function UserSettings({ userId }: { userId: string }) {
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const [edit, setEdit] = useState(false);
|
|
||||||
const [values, setValues] = useState(null);
|
|
||||||
const [tab, setTab] = useState<Key>('details');
|
const [tab, setTab] = useState<Key>('details');
|
||||||
const { get, useQuery } = useApi();
|
const { data: user, isLoading } = useUser(userId, { gcTime: 0 });
|
||||||
const { showToast } = useToasts();
|
|
||||||
const { data, isLoading } = useQuery({
|
|
||||||
queryKey: ['user', userId],
|
|
||||||
queryFn: () => {
|
|
||||||
if (userId) {
|
|
||||||
return get(`/users/${userId}`);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
gcTime: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleSave = (data: any) => {
|
if (isLoading) {
|
||||||
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
|
||||||
if (data) {
|
|
||||||
setValues(state => ({ ...state, ...data }));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (edit) {
|
|
||||||
setEdit(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (data) {
|
|
||||||
setValues(data);
|
|
||||||
}
|
|
||||||
}, [data]);
|
|
||||||
|
|
||||||
if (isLoading || !values) {
|
|
||||||
return <Loading />;
|
return <Loading />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageHeader title={values?.username} />
|
<PageHeader title={user?.username} />
|
||||||
<Tabs selectedKey={tab} onSelect={setTab} style={{ marginBottom: 30, fontSize: 14 }}>
|
<Tabs selectedKey={tab} onSelect={setTab} style={{ marginBottom: 30, fontSize: 14 }}>
|
||||||
<Item key="details">{formatMessage(labels.details)}</Item>
|
<Item key="details">{formatMessage(labels.details)}</Item>
|
||||||
<Item key="websites">{formatMessage(labels.websites)}</Item>
|
<Item key="websites">{formatMessage(labels.websites)}</Item>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
{tab === 'details' && <UserEditForm userId={userId} data={values} onSave={handleSave} />}
|
{tab === 'details' && <UserEditForm userId={userId} data={user} />}
|
||||||
{tab === 'websites' && <UserWebsites userId={userId} />}
|
{tab === 'websites' && <UserWebsites userId={userId} />}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
18
src/app/(main)/settings/users/[id]/UserWebsites.tsx
Normal file
18
src/app/(main)/settings/users/[id]/UserWebsites.tsx
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
'use client';
|
||||||
|
import WebsitesTable from 'app/(main)/settings/websites/WebsitesTable';
|
||||||
|
import DataTable from 'components/common/DataTable';
|
||||||
|
import { useWebsites } from 'components/hooks';
|
||||||
|
|
||||||
|
export function UserWebsites({ userId }) {
|
||||||
|
const queryResult = useWebsites({ userId });
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DataTable queryResult={queryResult}>
|
||||||
|
{({ data }) => (
|
||||||
|
<WebsitesTable data={data} showActions={true} allowEdit={true} allowView={true} />
|
||||||
|
)}
|
||||||
|
</DataTable>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default UserWebsites;
|
@ -1,5 +1,5 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import { useContext, useEffect, useState, Key } from 'react';
|
import { useState, Key } from 'react';
|
||||||
import { Item, Tabs, useToasts, Button, Text, Icon, Icons, Loading } from 'react-basics';
|
import { Item, Tabs, useToasts, Button, Text, Icon, Icons, Loading } from 'react-basics';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
@ -8,56 +8,42 @@ import WebsiteEditForm from './[id]/WebsiteEditForm';
|
|||||||
import WebsiteData from './[id]/WebsiteData';
|
import WebsiteData from './[id]/WebsiteData';
|
||||||
import TrackingCode from './[id]/TrackingCode';
|
import TrackingCode from './[id]/TrackingCode';
|
||||||
import ShareUrl from './[id]/ShareUrl';
|
import ShareUrl from './[id]/ShareUrl';
|
||||||
import { useApi } from 'components/hooks';
|
import { useWebsite, useMessages } from 'components/hooks';
|
||||||
import { useMessages } from 'components/hooks';
|
import { touch } from 'store/cache';
|
||||||
import SettingsContext from '../SettingsContext';
|
|
||||||
|
|
||||||
export function WebsiteSettings({ websiteId, openExternal = false }) {
|
export function WebsiteSettings({ websiteId, openExternal = false }) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { get, useQuery } = useApi();
|
|
||||||
const { showToast } = useToasts();
|
const { showToast } = useToasts();
|
||||||
const { websitesUrl, websitesPath, settingsPath } = useContext(SettingsContext);
|
|
||||||
const { data, isLoading } = useQuery({
|
const { data: website, isLoading } = useWebsite(websiteId, { gcTime: 0 });
|
||||||
queryKey: ['website', websiteId],
|
|
||||||
queryFn: () => get(`${websitesUrl}/${websiteId}`),
|
|
||||||
enabled: !!websiteId,
|
|
||||||
gcTime: 0,
|
|
||||||
});
|
|
||||||
const [values, setValues] = useState(null);
|
|
||||||
const [tab, setTab] = useState<Key>('details');
|
const [tab, setTab] = useState<Key>('details');
|
||||||
|
|
||||||
const showSuccess = () => {
|
const showSuccess = () => {
|
||||||
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSave = (data: any) => {
|
const handleSave = () => {
|
||||||
showSuccess();
|
showSuccess();
|
||||||
setValues((state: any) => ({ ...state, ...data }));
|
touch('websites');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleReset = async (value: string) => {
|
const handleReset = async (value: string) => {
|
||||||
if (value === 'delete') {
|
if (value === 'delete') {
|
||||||
router.push(settingsPath);
|
router.push('/settings/websites');
|
||||||
} else if (value === 'reset') {
|
} else if (value === 'reset') {
|
||||||
showSuccess();
|
showSuccess();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
if (isLoading) {
|
||||||
if (data) {
|
|
||||||
setValues(data);
|
|
||||||
}
|
|
||||||
}, [data]);
|
|
||||||
|
|
||||||
if (isLoading || !values) {
|
|
||||||
return <Loading position="page" />;
|
return <Loading position="page" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageHeader title={values?.name}>
|
<PageHeader title={website?.name}>
|
||||||
<Link href={`${websitesPath}/${websiteId}`} target={openExternal ? '_blank' : null}>
|
<Link href={`/websites/${websiteId}`} target={openExternal ? '_blank' : null}>
|
||||||
<Button variant="primary">
|
<Button variant="primary">
|
||||||
<Icon>
|
<Icon>
|
||||||
<Icons.External />
|
<Icons.External />
|
||||||
@ -73,10 +59,10 @@ export function WebsiteSettings({ websiteId, openExternal = false }) {
|
|||||||
<Item key="data">{formatMessage(labels.data)}</Item>
|
<Item key="data">{formatMessage(labels.data)}</Item>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
{tab === 'details' && (
|
{tab === 'details' && (
|
||||||
<WebsiteEditForm websiteId={websiteId} data={values} onSave={handleSave} />
|
<WebsiteEditForm websiteId={websiteId} data={website} onSave={handleSave} />
|
||||||
)}
|
)}
|
||||||
{tab === 'tracking' && <TrackingCode websiteId={websiteId} />}
|
{tab === 'tracking' && <TrackingCode websiteId={websiteId} />}
|
||||||
{tab === 'share' && <ShareUrl websiteId={websiteId} data={values} onSave={handleSave} />}
|
{tab === 'share' && <ShareUrl websiteId={websiteId} data={website} onSave={handleSave} />}
|
||||||
{tab === 'data' && <WebsiteData websiteId={websiteId} onSave={handleReset} />}
|
{tab === 'data' && <WebsiteData websiteId={websiteId} onSave={handleReset} />}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import { useUser } from 'components/hooks';
|
import { useLogin } from 'components/hooks';
|
||||||
import WebsitesDataTable from './WebsitesDataTable';
|
import WebsitesDataTable from './WebsitesDataTable';
|
||||||
import WebsitesHeader from './WebsitesHeader';
|
import WebsitesHeader from './WebsitesHeader';
|
||||||
|
|
||||||
export default function Websites() {
|
export default function Websites() {
|
||||||
const { user } = useUser();
|
const { user } = useLogin();
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WebsitesHeader showActions={user.role !== 'view-only'} />
|
<WebsitesHeader showActions={user.role !== 'view-only'} />
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import { ReactNode } from 'react';
|
import { ReactNode } from 'react';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { Button, Text, Icon, Icons, GridTable, GridColumn, useBreakpoint } from 'react-basics';
|
import { Button, Text, Icon, Icons, GridTable, GridColumn, useBreakpoint } from 'react-basics';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages, useLogin } from 'components/hooks';
|
||||||
import { useUser } from 'components/hooks';
|
|
||||||
|
|
||||||
export interface WebsitesTableProps {
|
export interface WebsitesTableProps {
|
||||||
data: any[];
|
data: any[];
|
||||||
@ -22,7 +21,7 @@ export function WebsitesTable({
|
|||||||
children,
|
children,
|
||||||
}: WebsitesTableProps) {
|
}: WebsitesTableProps) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { user } = useUser();
|
const { user } = useLogin();
|
||||||
const breakpoint = useBreakpoint();
|
const breakpoint = useBreakpoint();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -32,13 +31,12 @@ export function WebsitesTable({
|
|||||||
{showActions && (
|
{showActions && (
|
||||||
<GridColumn name="action" label=" " alignment="end">
|
<GridColumn name="action" label=" " alignment="end">
|
||||||
{row => {
|
{row => {
|
||||||
const { id } = row;
|
const { id, userId } = row;
|
||||||
const isOwner = row.userId === user.id || row.teamId === teamId;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{allowEdit && isOwner && (
|
{allowEdit && !teamId && user.id === userId && (
|
||||||
<Link href={`/settings/${id}`}>
|
<Link href={`/settings/websites/${id}`}>
|
||||||
<Button>
|
<Button>
|
||||||
<Icon>
|
<Icon>
|
||||||
<Icons.Edit />
|
<Icons.Edit />
|
||||||
|
@ -10,21 +10,20 @@ import {
|
|||||||
} from 'react-basics';
|
} from 'react-basics';
|
||||||
import { useContext, useEffect, useMemo, useRef, useState } from 'react';
|
import { useContext, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { getRandomChars } from 'next-basics';
|
import { getRandomChars } from 'next-basics';
|
||||||
import { useApi } from 'components/hooks';
|
import { useApi, useMessages } from 'components/hooks';
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
import SettingsContext from '../../SettingsContext';
|
import SettingsContext from '../../SettingsContext';
|
||||||
|
|
||||||
const generateId = () => getRandomChars(16);
|
const generateId = () => getRandomChars(16);
|
||||||
|
|
||||||
export function ShareUrl({ websiteId, data, onSave }) {
|
export function ShareUrl({ websiteId, data, onSave }) {
|
||||||
const ref = useRef(null);
|
const ref = useRef(null);
|
||||||
const { shareUrl, websitesUrl } = useContext(SettingsContext);
|
const { shareUrl } = useContext(SettingsContext);
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { name, shareId } = data;
|
const { name, shareId } = data;
|
||||||
const [id, setId] = useState(shareId);
|
const [id, setId] = useState(shareId);
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
const { mutate, error } = useMutation({
|
const { mutate, error } = useMutation({
|
||||||
mutationFn: (data: any) => post(`${websitesUrl}/${websiteId}`, data),
|
mutationFn: (data: any) => post(`/websites/${websiteId}`, data),
|
||||||
});
|
});
|
||||||
const url = useMemo(
|
const url = useMemo(
|
||||||
() => `${shareUrl}${process.env.basePath}/share/${id}/${encodeURIComponent(name)}`,
|
() => `${shareUrl}${process.env.basePath}/share/${id}/${encodeURIComponent(name)}`,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { TextArea } from 'react-basics';
|
import { TextArea } from 'react-basics';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages, useConfig } from 'components/hooks';
|
||||||
import { useConfig } from 'components/hooks';
|
|
||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
import SettingsContext from '../../SettingsContext';
|
import SettingsContext from '../../SettingsContext';
|
||||||
|
|
||||||
|
@ -1,16 +1,7 @@
|
|||||||
import {
|
import { useApi, useMessages } from 'components/hooks';
|
||||||
Button,
|
|
||||||
Form,
|
|
||||||
FormRow,
|
|
||||||
FormButtons,
|
|
||||||
FormInput,
|
|
||||||
SubmitButton,
|
|
||||||
TextField,
|
|
||||||
} from 'react-basics';
|
|
||||||
import { useApi } from 'components/hooks';
|
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
import SettingsContext from '../../SettingsContext';
|
import SettingsContext from '../../SettingsContext';
|
||||||
|
import TypeConfirmationForm from 'components/common/TypeConfirmationForm';
|
||||||
|
|
||||||
const CONFIRM_VALUE = 'DELETE';
|
const CONFIRM_VALUE = 'DELETE';
|
||||||
|
|
||||||
@ -23,40 +14,32 @@ export function WebsiteDeleteForm({
|
|||||||
onSave?: () => void;
|
onSave?: () => void;
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { websitesUrl } = useContext(SettingsContext);
|
const { websitesUrl } = useContext(SettingsContext);
|
||||||
const { del, useMutation } = useApi();
|
const { del, useMutation } = useApi();
|
||||||
const { mutate, error } = useMutation({
|
const { mutate, isPending, error } = useMutation({
|
||||||
mutationFn: (data: any) => del(`${websitesUrl}/${websiteId}`, data),
|
mutationFn: (data: any) => del(`${websitesUrl}/${websiteId}`, data),
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmit = async (data: any) => {
|
const handleConfirm = async () => {
|
||||||
mutate(data, {
|
mutate(null, {
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
onSave();
|
onSave?.();
|
||||||
onClose();
|
onClose?.();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form onSubmit={handleSubmit} error={error}>
|
<TypeConfirmationForm
|
||||||
<p>
|
confirmationValue={CONFIRM_VALUE}
|
||||||
<FormattedMessage
|
onConfirm={handleConfirm}
|
||||||
{...messages.actionConfirmation}
|
onClose={onClose}
|
||||||
values={{ confirmation: <b>{CONFIRM_VALUE}</b> }}
|
isLoading={isPending}
|
||||||
/>
|
error={error}
|
||||||
</p>
|
buttonLabel={formatMessage(labels.delete)}
|
||||||
<FormRow label={formatMessage(labels.confirm)}>
|
buttonVariant="danger"
|
||||||
<FormInput name="confirmation" rules={{ validate: value => value === CONFIRM_VALUE }}>
|
/>
|
||||||
<TextField autoComplete="off" />
|
|
||||||
</FormInput>
|
|
||||||
</FormRow>
|
|
||||||
<FormButtons flex>
|
|
||||||
<SubmitButton variant="danger">{formatMessage(labels.delete)}</SubmitButton>
|
|
||||||
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
|
|
||||||
</FormButtons>
|
|
||||||
</Form>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +1,5 @@
|
|||||||
import {
|
import { useApi, useMessages } from 'components/hooks';
|
||||||
Button,
|
import TypeConfirmationForm from 'components/common/TypeConfirmationForm';
|
||||||
Form,
|
|
||||||
FormRow,
|
|
||||||
FormButtons,
|
|
||||||
FormInput,
|
|
||||||
SubmitButton,
|
|
||||||
TextField,
|
|
||||||
} from 'react-basics';
|
|
||||||
import { useApi } from 'components/hooks';
|
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
import { useContext } from 'react';
|
|
||||||
import SettingsContext from '../../SettingsContext';
|
|
||||||
|
|
||||||
const CONFIRM_VALUE = 'RESET';
|
const CONFIRM_VALUE = 'RESET';
|
||||||
|
|
||||||
@ -23,40 +12,30 @@ export function WebsiteResetForm({
|
|||||||
onSave?: () => void;
|
onSave?: () => void;
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { websitesUrl } = useContext(SettingsContext);
|
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
const { mutate, error } = useMutation({
|
const { mutate, isPending, error } = useMutation({
|
||||||
mutationFn: (data: any) => post(`${websitesUrl}/${websiteId}/reset`, data),
|
mutationFn: (data: any) => post(`/websites/${websiteId}/reset`, data),
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmit = async (data: any) => {
|
const handleConfirm = async () => {
|
||||||
mutate(data, {
|
mutate(null, {
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
onSave();
|
onSave?.();
|
||||||
onClose();
|
onClose?.();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form onSubmit={handleSubmit} error={error}>
|
<TypeConfirmationForm
|
||||||
<p>
|
confirmationValue={CONFIRM_VALUE}
|
||||||
<FormattedMessage
|
onConfirm={handleConfirm}
|
||||||
{...messages.actionConfirmation}
|
onClose={onClose}
|
||||||
values={{ confirmation: <b>{CONFIRM_VALUE}</b> }}
|
isLoading={isPending}
|
||||||
/>
|
error={error}
|
||||||
</p>
|
buttonLabel={formatMessage(labels.reset)}
|
||||||
<FormRow label={formatMessage(labels.confirm)}>
|
/>
|
||||||
<FormInput name="confirm" rules={{ validate: value => value === CONFIRM_VALUE }}>
|
|
||||||
<TextField autoComplete="off" />
|
|
||||||
</FormInput>
|
|
||||||
</FormRow>
|
|
||||||
<FormButtons flex>
|
|
||||||
<SubmitButton variant="danger">{formatMessage(labels.reset)}</SubmitButton>
|
|
||||||
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
|
|
||||||
</FormButtons>
|
|
||||||
</Form>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
'use client';
|
|
||||||
import { useContext } from 'react';
|
|
||||||
import TeamsContext from 'app/(main)/teams/TeamsContext';
|
|
||||||
import WebsitesDataTable from 'app/(main)/settings/websites/WebsitesDataTable';
|
|
||||||
|
|
||||||
export default function TeamWebsites() {
|
|
||||||
const team = useContext(TeamsContext);
|
|
||||||
|
|
||||||
if (!team) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return <WebsitesDataTable teamId={team.id} />;
|
|
||||||
}
|
|
@ -1,11 +1,11 @@
|
|||||||
import TeamWebsites from './TeamWebsites';
|
import WebsitesDataTable from 'app/(main)/settings/websites/WebsitesDataTable';
|
||||||
import WebsitesHeader from 'app/(main)/settings/websites/WebsitesHeader';
|
import WebsitesHeader from 'app/(main)/settings/websites/WebsitesHeader';
|
||||||
|
|
||||||
export default function TeamWebsitesPage({ params: { id } }: { params: { id: string } }) {
|
export default function TeamWebsitesPage({ params: { id } }: { params: { id: string } }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WebsitesHeader teamId={id} />
|
<WebsitesHeader teamId={id} />
|
||||||
<TeamWebsites />
|
<WebsitesDataTable teamId={id} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import WebsitesDataTable from '../settings/websites/WebsitesDataTable';
|
import WebsitesDataTable from '../settings/websites/WebsitesDataTable';
|
||||||
import { useUser } from 'components/hooks';
|
import { useLogin } from 'components/hooks';
|
||||||
|
|
||||||
export function WebsitesBrowse() {
|
export function WebsitesBrowse() {
|
||||||
const { user } = useUser();
|
const { user } = useLogin();
|
||||||
const allowEdit = !process.env.cloudMode;
|
const allowEdit = !process.env.cloudMode;
|
||||||
|
|
||||||
return <WebsitesDataTable userId={user.id} allowEdit={allowEdit} />;
|
return <WebsitesDataTable userId={user.id} allowEdit={allowEdit} />;
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
import { useState } from 'react';
|
|
||||||
import { Button, LoadingButton, Form, FormButtons } from 'react-basics';
|
|
||||||
import { useMessages } from 'components/hooks';
|
|
||||||
|
|
||||||
export interface ConfirmDeleteFormProps {
|
|
||||||
name: string;
|
|
||||||
onConfirm?: () => void;
|
|
||||||
onClose?: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ConfirmDeleteForm({ name, onConfirm, onClose }: ConfirmDeleteFormProps) {
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
|
|
||||||
|
|
||||||
const handleConfirm = () => {
|
|
||||||
setLoading(true);
|
|
||||||
onConfirm();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Form>
|
|
||||||
<p>
|
|
||||||
<FormattedMessage {...messages.confirmDelete} values={{ target: <b>{name}</b> }} />
|
|
||||||
</p>
|
|
||||||
<FormButtons flex>
|
|
||||||
<LoadingButton isLoading={loading} onClick={handleConfirm} variant="danger">
|
|
||||||
{formatMessage(labels.delete)}
|
|
||||||
</LoadingButton>
|
|
||||||
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
|
|
||||||
</FormButtons>
|
|
||||||
</Form>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ConfirmDeleteForm;
|
|
39
src/components/common/ConfirmationForm.tsx
Normal file
39
src/components/common/ConfirmationForm.tsx
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { ReactNode } from 'react';
|
||||||
|
import { Button, LoadingButton, Form, FormButtons } from 'react-basics';
|
||||||
|
import { useMessages } from 'components/hooks';
|
||||||
|
|
||||||
|
export interface ConfirmationFormProps {
|
||||||
|
message: ReactNode;
|
||||||
|
buttonLabel?: ReactNode;
|
||||||
|
buttonVariant?: 'none' | 'primary' | 'secondary' | 'quiet' | 'danger';
|
||||||
|
isLoading?: boolean;
|
||||||
|
error?: string | Error;
|
||||||
|
onConfirm?: () => void;
|
||||||
|
onClose?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ConfirmationForm({
|
||||||
|
message,
|
||||||
|
buttonLabel,
|
||||||
|
buttonVariant,
|
||||||
|
isLoading,
|
||||||
|
error,
|
||||||
|
onConfirm,
|
||||||
|
onClose,
|
||||||
|
}: ConfirmationFormProps) {
|
||||||
|
const { formatMessage, labels } = useMessages();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form error={error}>
|
||||||
|
<p>{message}</p>
|
||||||
|
<FormButtons flex>
|
||||||
|
<LoadingButton isLoading={isLoading} onClick={onConfirm} variant={buttonVariant}>
|
||||||
|
{buttonLabel || formatMessage(labels.ok)}
|
||||||
|
</LoadingButton>
|
||||||
|
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
|
||||||
|
</FormButtons>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ConfirmationForm;
|
58
src/components/common/TypeConfirmationForm.tsx
Normal file
58
src/components/common/TypeConfirmationForm.tsx
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Form,
|
||||||
|
FormButtons,
|
||||||
|
FormRow,
|
||||||
|
FormInput,
|
||||||
|
TextField,
|
||||||
|
SubmitButton,
|
||||||
|
} from 'react-basics';
|
||||||
|
import { useMessages } from 'components/hooks';
|
||||||
|
|
||||||
|
export function TypeConfirmationForm({
|
||||||
|
confirmationValue,
|
||||||
|
buttonLabel,
|
||||||
|
buttonVariant,
|
||||||
|
isLoading,
|
||||||
|
error,
|
||||||
|
onConfirm,
|
||||||
|
onClose,
|
||||||
|
}: {
|
||||||
|
confirmationValue: string;
|
||||||
|
buttonLabel?: string;
|
||||||
|
buttonVariant?: 'none' | 'primary' | 'secondary' | 'quiet' | 'danger';
|
||||||
|
isLoading?: boolean;
|
||||||
|
error?: string | Error;
|
||||||
|
onConfirm?: () => void;
|
||||||
|
onClose?: () => void;
|
||||||
|
}) {
|
||||||
|
const { formatMessage, labels, messages, FormattedMessage } = useMessages();
|
||||||
|
|
||||||
|
if (!confirmationValue) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form onSubmit={onConfirm} error={error}>
|
||||||
|
<p>
|
||||||
|
<FormattedMessage
|
||||||
|
{...messages.actionConfirmation}
|
||||||
|
values={{ confirmation: <b>{confirmationValue}</b> }}
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
<FormRow label={formatMessage(labels.confirm)}>
|
||||||
|
<FormInput name="confirm" rules={{ validate: value => value === confirmationValue }}>
|
||||||
|
<TextField autoComplete="off" />
|
||||||
|
</FormInput>
|
||||||
|
</FormRow>
|
||||||
|
<FormButtons flex>
|
||||||
|
<SubmitButton isLoading={isLoading} variant={buttonVariant}>
|
||||||
|
{buttonLabel || formatMessage(labels.ok)}
|
||||||
|
</SubmitButton>
|
||||||
|
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
|
||||||
|
</FormButtons>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TypeConfirmationForm;
|
@ -8,7 +8,9 @@ export * from './queries/useShareToken';
|
|||||||
export * from './queries/useTeam';
|
export * from './queries/useTeam';
|
||||||
export * from './queries/useTeamWebsites';
|
export * from './queries/useTeamWebsites';
|
||||||
export * from './queries/useUser';
|
export * from './queries/useUser';
|
||||||
|
export * from './queries/useUsers';
|
||||||
export * from './queries/useWebsite';
|
export * from './queries/useWebsite';
|
||||||
|
export * from './queries/useWebsites';
|
||||||
export * from './useCountryNames';
|
export * from './useCountryNames';
|
||||||
export * from './useDateRange';
|
export * from './useDateRange';
|
||||||
export * from './useDocumentClick';
|
export * from './useDocumentClick';
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
|
import useStore, { setUser } from 'store/app';
|
||||||
import useApi from './useApi';
|
import useApi from './useApi';
|
||||||
import useUser from './useUser';
|
|
||||||
|
const selector = (state: { user: any }) => state.user;
|
||||||
|
|
||||||
export function useLogin() {
|
export function useLogin() {
|
||||||
const { get, useQuery } = useApi();
|
const { get, useQuery } = useApi();
|
||||||
const { user, setUser } = useUser();
|
const user = useStore(selector);
|
||||||
|
|
||||||
const query = useQuery({
|
const query = useQuery({
|
||||||
queryKey: ['login'],
|
queryKey: ['login'],
|
||||||
@ -14,6 +16,7 @@ export function useLogin() {
|
|||||||
|
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
enabled: !user,
|
||||||
});
|
});
|
||||||
|
|
||||||
return { user, ...query };
|
return { user, ...query };
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import useStore, { setUser } from 'store/app';
|
import useApi from './useApi';
|
||||||
|
|
||||||
const selector = (state: { user: any }) => state.user;
|
export function useUser(userId: string, options?: { [key: string]: any }) {
|
||||||
|
const { get, useQuery } = useApi();
|
||||||
export function useUser() {
|
return useQuery({
|
||||||
const user = useStore(selector);
|
queryKey: ['users', userId],
|
||||||
|
queryFn: () => get(`/users/${userId}`),
|
||||||
return { user, setUser };
|
enabled: !!userId,
|
||||||
|
...options,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default useUser;
|
export default useUser;
|
||||||
|
19
src/components/hooks/queries/useUsers.ts
Normal file
19
src/components/hooks/queries/useUsers.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import useApi from './useApi';
|
||||||
|
import useFilterQuery from './useFilterQuery';
|
||||||
|
import useCache from 'store/cache';
|
||||||
|
|
||||||
|
export function useUsers() {
|
||||||
|
const { get } = useApi();
|
||||||
|
const modified = useCache((state: any) => state?.users);
|
||||||
|
|
||||||
|
return useFilterQuery({
|
||||||
|
queryKey: ['users', { modified }],
|
||||||
|
queryFn: (params: any) => {
|
||||||
|
return get('/admin/users', {
|
||||||
|
...params,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useUsers;
|
@ -1,11 +1,12 @@
|
|||||||
import useApi from './useApi';
|
import useApi from './useApi';
|
||||||
|
|
||||||
export function useWebsite(websiteId: string) {
|
export function useWebsite(websiteId: string, options?: { [key: string]: any }) {
|
||||||
const { get, useQuery } = useApi();
|
const { get, useQuery } = useApi();
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['websites', websiteId],
|
queryKey: ['websites', websiteId],
|
||||||
queryFn: () => get(`/websites/${websiteId}`),
|
queryFn: () => get(`/websites/${websiteId}`),
|
||||||
enabled: !!websiteId,
|
enabled: !!websiteId,
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ export function useWebsites({ userId, teamId }: { userId?: string; teamId?: stri
|
|||||||
return useFilterQuery({
|
return useFilterQuery({
|
||||||
queryKey: ['websites', { userId, teamId, modified }],
|
queryKey: ['websites', { userId, teamId, modified }],
|
||||||
queryFn: (params: any) => {
|
queryFn: (params: any) => {
|
||||||
return get(teamId ? `/teams/${teamId}/websites` : '/websites', {
|
return get(teamId ? `/teams/${teamId}/websites` : `/users/${userId}/websites`, {
|
||||||
...params,
|
...params,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -4,8 +4,8 @@ import { DATE_RANGE_CONFIG, DEFAULT_DATE_RANGE } from 'lib/constants';
|
|||||||
import websiteStore, { setWebsiteDateRange } from 'store/websites';
|
import websiteStore, { setWebsiteDateRange } from 'store/websites';
|
||||||
import appStore, { setDateRange } from 'store/app';
|
import appStore, { setDateRange } from 'store/app';
|
||||||
import { DateRange } from 'lib/types';
|
import { DateRange } from 'lib/types';
|
||||||
import useLocale from './useLocale';
|
import { useLocale } from './useLocale';
|
||||||
import { useApi } from 'components/hooks';
|
import { useApi } from './queries/useApi';
|
||||||
|
|
||||||
export function useDateRange(websiteId?: string) {
|
export function useDateRange(websiteId?: string) {
|
||||||
const { get } = useApi();
|
const { get } = useApi();
|
||||||
|
@ -2,14 +2,14 @@ import { Icon, Button, PopupTrigger, Popup, Menu, Item, Text } from 'react-basic
|
|||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import Icons from 'components/icons';
|
import Icons from 'components/icons';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages } from 'components/hooks';
|
||||||
import { useUser } from 'components/hooks';
|
import { useLogin } from 'components/hooks';
|
||||||
import { useLocale } from 'components/hooks';
|
import { useLocale } from 'components/hooks';
|
||||||
import { CURRENT_VERSION } from 'lib/constants';
|
import { CURRENT_VERSION } from 'lib/constants';
|
||||||
import styles from './ProfileButton.module.css';
|
import styles from './ProfileButton.module.css';
|
||||||
|
|
||||||
export function ProfileButton() {
|
export function ProfileButton() {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { user } = useUser();
|
const { user } = useLogin();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { dir } = useLocale();
|
const { dir } = useLocale();
|
||||||
const cloudMode = Boolean(process.env.cloudMode);
|
const cloudMode = Boolean(process.env.cloudMode);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { defineMessages } from 'react-intl';
|
import { defineMessages } from 'react-intl';
|
||||||
|
|
||||||
export const labels = defineMessages({
|
export const labels = defineMessages({
|
||||||
|
ok: { id: 'label.ok', defaultMessage: 'OK' },
|
||||||
unknown: { id: 'label.unknown', defaultMessage: 'Unknown' },
|
unknown: { id: 'label.unknown', defaultMessage: 'Unknown' },
|
||||||
required: { id: 'label.required', defaultMessage: 'Required' },
|
required: { id: 'label.required', defaultMessage: 'Required' },
|
||||||
save: { id: 'label.save', defaultMessage: 'Save' },
|
save: { id: 'label.save', defaultMessage: 'Save' },
|
||||||
@ -50,6 +51,7 @@ export const labels = defineMessages({
|
|||||||
websiteId: { id: 'label.website-id', defaultMessage: 'Website ID' },
|
websiteId: { id: 'label.website-id', defaultMessage: 'Website ID' },
|
||||||
resetWebsite: { id: 'label.reset-website', defaultMessage: 'Reset website' },
|
resetWebsite: { id: 'label.reset-website', defaultMessage: 'Reset website' },
|
||||||
deleteWebsite: { id: 'label.delete-website', defaultMessage: 'Delete website' },
|
deleteWebsite: { id: 'label.delete-website', defaultMessage: 'Delete website' },
|
||||||
|
deleteReport: { id: 'label.delete-report', defaultMessage: 'Delete report' },
|
||||||
reset: { id: 'label.reset', defaultMessage: 'Reset' },
|
reset: { id: 'label.reset', defaultMessage: 'Reset' },
|
||||||
addWebsite: { id: 'label.add-website', defaultMessage: 'Add website' },
|
addWebsite: { id: 'label.add-website', defaultMessage: 'Add website' },
|
||||||
addMember: { id: 'label.add-member', defaultMessage: 'Add member' },
|
addMember: { id: 'label.add-member', defaultMessage: 'Add member' },
|
||||||
|
@ -50,7 +50,7 @@ export * from 'app/(main)/settings/websites/WebsitesTable';
|
|||||||
|
|
||||||
export * from 'app/(main)/settings/SettingsContext';
|
export * from 'app/(main)/settings/SettingsContext';
|
||||||
|
|
||||||
export * from 'components/common/ConfirmDeleteForm';
|
export * from 'components/common/TypeConfirmationForm';
|
||||||
export * from 'components/common/DataTable';
|
export * from 'components/common/DataTable';
|
||||||
export * from 'components/common/Empty';
|
export * from 'components/common/Empty';
|
||||||
export * from 'components/common/ErrorBoundary';
|
export * from 'components/common/ErrorBoundary';
|
||||||
|
@ -44,7 +44,20 @@ export default async (
|
|||||||
|
|
||||||
const { page, query, pageSize } = req.query;
|
const { page, query, pageSize } = req.query;
|
||||||
|
|
||||||
const users = await getUsers({ page, query, pageSize: +pageSize || undefined });
|
const users = await getUsers(
|
||||||
|
{ page, query, pageSize: +pageSize || undefined },
|
||||||
|
{
|
||||||
|
include: {
|
||||||
|
_count: {
|
||||||
|
select: {
|
||||||
|
website: {
|
||||||
|
where: { deletedAt: null },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return ok(res, users);
|
return ok(res, users);
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ export async function getUsers(
|
|||||||
...pageFilters,
|
...pageFilters,
|
||||||
...(options?.include && { include: options.include }),
|
...(options?.include && { include: options.include }),
|
||||||
})
|
})
|
||||||
.then(a => {
|
.then((a: { [x: string]: any; password: any }[]) => {
|
||||||
return a.map(({ password, ...rest }) => rest);
|
return a.map(({ password, ...rest }) => rest);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ export async function deleteUser(
|
|||||||
User,
|
User,
|
||||||
]
|
]
|
||||||
> {
|
> {
|
||||||
const { client } = prisma;
|
const { client, transaction } = prisma;
|
||||||
const cloudMode = process.env.CLOUD_MODE;
|
const cloudMode = process.env.CLOUD_MODE;
|
||||||
|
|
||||||
const websites = await client.website.findMany({
|
const websites = await client.website.findMany({
|
||||||
@ -190,7 +190,7 @@ export async function deleteUser(
|
|||||||
const teamIds = teams.map(a => a.id);
|
const teamIds = teams.map(a => a.id);
|
||||||
|
|
||||||
if (cloudMode) {
|
if (cloudMode) {
|
||||||
return client.transaction([
|
return transaction([
|
||||||
client.website.updateMany({
|
client.website.updateMany({
|
||||||
data: {
|
data: {
|
||||||
deletedAt: new Date(),
|
deletedAt: new Date(),
|
||||||
@ -209,70 +209,68 @@ export async function deleteUser(
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return client
|
return transaction([
|
||||||
.transaction([
|
client.eventData.deleteMany({
|
||||||
client.eventData.deleteMany({
|
where: { websiteId: { in: websiteIds } },
|
||||||
where: { websiteId: { in: websiteIds } },
|
}),
|
||||||
}),
|
client.websiteEvent.deleteMany({
|
||||||
client.websiteEvent.deleteMany({
|
where: { websiteId: { in: websiteIds } },
|
||||||
where: { websiteId: { in: websiteIds } },
|
}),
|
||||||
}),
|
client.session.deleteMany({
|
||||||
client.session.deleteMany({
|
where: { websiteId: { in: websiteIds } },
|
||||||
where: { websiteId: { in: websiteIds } },
|
}),
|
||||||
}),
|
client.teamUser.deleteMany({
|
||||||
client.teamUser.deleteMany({
|
where: {
|
||||||
where: {
|
OR: [
|
||||||
OR: [
|
{
|
||||||
{
|
teamId: {
|
||||||
teamId: {
|
in: teamIds,
|
||||||
in: teamIds,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
|
||||||
userId,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
client.team.deleteMany({
|
|
||||||
where: {
|
|
||||||
id: {
|
|
||||||
in: teamIds,
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
userId,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
client.team.deleteMany({
|
||||||
|
where: {
|
||||||
|
id: {
|
||||||
|
in: teamIds,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
client.report.deleteMany({
|
}),
|
||||||
where: {
|
client.report.deleteMany({
|
||||||
OR: [
|
where: {
|
||||||
{
|
OR: [
|
||||||
websiteId: {
|
{
|
||||||
in: websiteIds,
|
websiteId: {
|
||||||
},
|
in: websiteIds,
|
||||||
},
|
},
|
||||||
{
|
},
|
||||||
userId,
|
{
|
||||||
},
|
userId,
|
||||||
],
|
},
|
||||||
},
|
],
|
||||||
}),
|
},
|
||||||
client.website.deleteMany({
|
}),
|
||||||
where: { id: { in: websiteIds } },
|
client.website.deleteMany({
|
||||||
}),
|
where: { id: { in: websiteIds } },
|
||||||
client.user.delete({
|
}),
|
||||||
where: {
|
client.user.delete({
|
||||||
id: userId,
|
where: {
|
||||||
},
|
id: userId,
|
||||||
}),
|
},
|
||||||
])
|
}),
|
||||||
.then(async (data: any) => {
|
]).then(async (data: any) => {
|
||||||
if (cache.enabled) {
|
if (cache.enabled) {
|
||||||
const ids = websites.map(a => a.id);
|
const ids = websites.map(a => a.id);
|
||||||
|
|
||||||
for (let i = 0; i < ids.length; i++) {
|
for (let i = 0; i < ids.length; i++) {
|
||||||
await cache.deleteWebsite(`website:${ids[i]}`);
|
await cache.deleteWebsite(`website:${ids[i]}`);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,12 @@ import { create } from 'zustand';
|
|||||||
|
|
||||||
const store = create(() => ({}));
|
const store = create(() => ({}));
|
||||||
|
|
||||||
export function setValue(key, value) {
|
export function setValue(key: string, value: any) {
|
||||||
store.setState({ [key]: value });
|
store.setState({ [key]: value });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function touch(key: string) {
|
||||||
|
setValue(key, Date.now());
|
||||||
|
}
|
||||||
|
|
||||||
export default store;
|
export default store;
|
||||||
|
Loading…
Reference in New Issue
Block a user