fix reset/delete

This commit is contained in:
Brian Cao 2022-10-11 19:43:02 -07:00
parent c147742d7a
commit bce4476d12
4 changed files with 28 additions and 24 deletions

View File

@ -5,7 +5,7 @@ import useFetch from 'hooks/useFetch';
import Dot from 'components/common/Dot'; import Dot from 'components/common/Dot';
import styles from './ActiveUsers.module.css'; import styles from './ActiveUsers.module.css';
export default function ActiveUsers({ websiteId, className, value, interval = 600000 }) { export default function ActiveUsers({ websiteId, className, value, interval = 60000 }) {
const url = websiteId ? `/websites/${websiteId}/active` : null; const url = websiteId ? `/websites/${websiteId}/active` : null;
const { data } = useFetch(url, { const { data } = useFetch(url, {
interval, interval,

View File

@ -46,7 +46,7 @@ export default function WebsiteSettings() {
icon={<LinkIcon />} icon={<LinkIcon />}
size="small" size="small"
tooltip={<FormattedMessage id="message.get-share-url" defaultMessage="Get share URL" />} tooltip={<FormattedMessage id="message.get-share-url" defaultMessage="Get share URL" />}
tooltipId={`button-share-${row.id}`} tooltipId={`button-share-${row.websiteUuid}`}
onClick={() => setShowUrl(row)} onClick={() => setShowUrl(row)}
/> />
)} )}
@ -56,42 +56,46 @@ export default function WebsiteSettings() {
tooltip={ tooltip={
<FormattedMessage id="message.get-tracking-code" defaultMessage="Get tracking code" /> <FormattedMessage id="message.get-tracking-code" defaultMessage="Get tracking code" />
} }
tooltipId={`button-code-${row.id}`} tooltipId={`button-code-${row.websiteUuid}`}
onClick={() => setShowCode(row)} onClick={() => setShowCode(row)}
/> />
<Button <Button
icon={<Pen />} icon={<Pen />}
size="small" size="small"
tooltip={<FormattedMessage id="label.edit" defaultMessage="Edit" />} tooltip={<FormattedMessage id="label.edit" defaultMessage="Edit" />}
tooltipId={`button-edit-${row.id}`} tooltipId={`button-edit-${row.websiteUuid}`}
onClick={() => setEditWebsite(row)} onClick={() => setEditWebsite(row)}
/> />
<Button <Button
icon={<Reset />} icon={<Reset />}
size="small" size="small"
tooltip={<FormattedMessage id="label.reset" defaultMessage="Reset" />} tooltip={<FormattedMessage id="label.reset" defaultMessage="Reset" />}
tooltipId={`button-reset-${row.id}`} tooltipId={`button-reset-${row.websiteUuid}`}
onClick={() => setResetWebsite(row)} onClick={() => setResetWebsite(row)}
/> />
<Button <Button
icon={<Trash />} icon={<Trash />}
size="small" size="small"
tooltip={<FormattedMessage id="label.delete" defaultMessage="Delete" />} tooltip={<FormattedMessage id="label.delete" defaultMessage="Delete" />}
tooltipId={`button-delete-${row.id}`} tooltipId={`button-delete-${row.websiteUuid}`}
onClick={() => setDeleteWebsite(row)} onClick={() => setDeleteWebsite(row)}
/> />
</ButtonLayout> </ButtonLayout>
); );
const DetailsLink = ({ id, name, domain }) => ( const DetailsLink = ({ websiteUuid, name, domain }) => (
<Link className={styles.detailLink} href="/websites/[...id]" as={`/websites/${id}/${name}`}> <Link
className={styles.detailLink}
href="/websites/[...id]"
as={`/websites/${websiteUuid}/${name}`}
>
<Favicon domain={domain} /> <Favicon domain={domain} />
<OverflowText tooltipId={`${id}-name`}>{name}</OverflowText> <OverflowText tooltipId={`${websiteUuid}-name`}>{name}</OverflowText>
</Link> </Link>
); );
const Domain = ({ domain, id }) => ( const Domain = ({ domain, websiteUuid }) => (
<OverflowText tooltipId={`${id}-domain`}>{domain}</OverflowText> <OverflowText tooltipId={`${websiteUuid}-domain`}>{domain}</OverflowText>
); );
const adminColumns = [ const adminColumns = [
@ -199,7 +203,7 @@ export default function WebsiteSettings() {
title={<FormattedMessage id="label.reset-website" defaultMessage="Reset statistics" />} title={<FormattedMessage id="label.reset-website" defaultMessage="Reset statistics" />}
> >
<ResetForm <ResetForm
values={{ type: 'websites', id: resetWebsite.id, name: resetWebsite.name }} values={{ type: 'websites', id: resetWebsite.websiteUuid, name: resetWebsite.name }}
onSave={handleSave} onSave={handleSave}
onClose={handleClose} onClose={handleClose}
/> />
@ -210,7 +214,7 @@ export default function WebsiteSettings() {
title={<FormattedMessage id="label.delete-website" defaultMessage="Delete website" />} title={<FormattedMessage id="label.delete-website" defaultMessage="Delete website" />}
> >
<DeleteForm <DeleteForm
values={{ type: 'websites', id: deleteWebsite.id, name: deleteWebsite.name }} values={{ type: 'websites', id: deleteWebsite.websiteUuid, name: deleteWebsite.name }}
onSave={handleSave} onSave={handleSave}
onClose={handleClose} onClose={handleClose}
/> />

View File

@ -1,27 +1,27 @@
import prisma from 'lib/prisma'; import prisma from 'lib/prisma';
import redis, { DELETED } from 'lib/redis'; import redis, { DELETED } from 'lib/redis';
import { getWebsiteById } from 'queries'; import { getWebsiteByUuid } from 'queries';
export async function deleteWebsite(websiteId) { export async function deleteWebsite(websiteId) {
const { client, transaction } = prisma; const { client, transaction } = prisma;
const { websiteUuid } = await getWebsiteById(websiteId); const { websiteUuid } = await getWebsiteByUuid(websiteId);
return transaction([ return transaction([
client.pageview.deleteMany({ client.pageview.deleteMany({
where: { session: { website: { id: websiteId } } }, where: { session: { website: { websiteUuid: websiteId } } },
}), }),
client.eventData.deleteMany({ client.eventData.deleteMany({
where: { event: { session: { website: { id: websiteId } } } }, where: { event: { session: { website: { websiteUuid: websiteId } } } },
}), }),
client.event.deleteMany({ client.event.deleteMany({
where: { session: { website: { id: websiteId } } }, where: { session: { website: { websiteUuid: websiteId } } },
}), }),
client.session.deleteMany({ client.session.deleteMany({
where: { website: { id: websiteId } }, where: { website: { websiteUuid: websiteId } },
}), }),
client.website.delete({ client.website.delete({
where: { id: websiteId }, where: { websiteUuid: websiteId },
}), }),
]).then(async res => { ]).then(async res => {
if (redis.client) { if (redis.client) {

View File

@ -5,16 +5,16 @@ export async function resetWebsite(websiteId) {
return transaction([ return transaction([
client.pageview.deleteMany({ client.pageview.deleteMany({
where: { session: { website: { id: websiteId } } }, where: { session: { website: { websiteUuid: websiteId } } },
}), }),
client.eventData.deleteMany({ client.eventData.deleteMany({
where: { event: { session: { website: { id: websiteId } } } }, where: { event: { session: { website: { websiteUuid: websiteId } } } },
}), }),
client.event.deleteMany({ client.event.deleteMany({
where: { session: { website: { id: websiteId } } }, where: { session: { website: { websiteUuid: websiteId } } },
}), }),
client.session.deleteMany({ client.session.deleteMany({
where: { website: { id: websiteId } }, where: { website: { websiteUuid: websiteId } },
}), }),
]); ]);
} }