Skip to content

Commit

Permalink
Fix docker compose activity stream (uselotus#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnida authored Nov 25, 2022
1 parent 4c78f69 commit 7b4ecfc
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 137 deletions.
4 changes: 2 additions & 2 deletions frontend/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,11 @@ export const Stripe = {
export const PaymentProcessorIntegration = {
getPaymentProcessorConnectionStatus: (): Promise<
PaymentProcessorStatusType[]
> => requests.get("api/payment_providers/"),
> => requests.get("/api/payment_providers/"),
connectPaymentProcessor: (
pp_info: PaymentProcessorConnectionRequestType
): Promise<PaymentProcessorConnectionResponseType> =>
requests.post("api/payment_providers/", { pp_info }),
requests.post("/api/payment_providers/", { pp_info }),
};

export const Invoices = {
Expand Down
251 changes: 127 additions & 124 deletions frontend/src/components/Settings/settings/tabs/ActivityTab.tsx
Original file line number Diff line number Diff line change
@@ -1,141 +1,144 @@
import React, {FC, Fragment, useEffect, useState} from "react";
import {useQuery, useMutation, useQueryClient} from "react-query";
import React, { FC, Fragment, useEffect, useState } from "react";
import { useQuery, useMutation, useQueryClient } from "react-query";
import dayjs from "dayjs";
import {Paper} from "../../../base/Paper";
import {Typography} from "antd";
import {Organization} from "../../../../api/api";
import { Paper } from "../../../base/Paper";
import { Typography } from "antd";
import { Organization } from "../../../../api/api";
import LoadingSpinner from "../../../LoadingSpinner";
import CustomPagination from "../../../CustomPagination/CustomPagination";

export default function ActivityStream() {
const [cursor, setCursor] = useState<string>("");
const [currentPage, setCurrentPage] = useState<number>(1);
const [next, setNext] = useState("");
const [previous, setPrevious] = useState("");
const [cursor, setCursor] = useState<string>("");
const [currentPage, setCurrentPage] = useState<number>(1);
const [next, setNext] = useState("");
const [previous, setPrevious] = useState("");

const {
data: activityItems, // organization is the data returned from the query
isLoading,
isError,
} = useQuery(
["stream", cursor],
() =>
Organization.getActionStream(cursor).then((res) => {
setNext(decodeURIComponent(res.next));
setPrevious(decodeURIComponent(res.previous));
return res;
}),
const {
data: activityItems, // organization is the data returned from the query
isLoading,
isError,
} = useQuery(
["stream", cursor],
() =>
Organization.getActionStream(cursor).then((res) => {
setNext(decodeURIComponent(res.next));
setPrevious(decodeURIComponent(res.previous));
return res;
}),

{
refetchOnMount: "always",
}
);
const queryClient = useQueryClient();

useEffect(() => {
if (activityItems !== undefined) {
setNext(decodeURIComponent(activityItems.next));
setPrevious(decodeURIComponent(activityItems.previous));
}
}, [activityItems]);

if ((isLoading || !activityItems) && !cursor) {
return (
<Fragment>
<Typography.Title level={2}>Activity Stream</Typography.Title>
<LoadingSpinner/>.
</Fragment>
);
{
refetchOnMount: "always",
}
if (activityItems?.results.length === 0) {
return (
<Fragment>
<Typography.Title level={2}>Activity Stream</Typography.Title>
<div className="align-center">
<h3 className="text-xl font-main align-center">No Activities</h3>
<div className="separator mb-5 mt-5"/>
</div>
</Fragment>
);
}

const handleMovements = (direction:"LEFT" | "RIGHT" | "START") => {
switch (direction){
case "LEFT":
if(currentPage == 1) return;
setCursor(previous);
setCurrentPage(currentPage - 1)
queryClient.invalidateQueries(["preview_events", cursor]);
return
case "RIGHT":
setCursor(next);
setCurrentPage(currentPage + 1)
queryClient.invalidateQueries(["preview_events", cursor]);
return;
case "START":
setCursor(null);
setCurrentPage(1)
queryClient.invalidateQueries(["preview_events", null]);
return;
}
);
const queryClient = useQueryClient();

useEffect(() => {
if (activityItems !== undefined) {
setNext(decodeURIComponent(activityItems.next));
setPrevious(decodeURIComponent(activityItems.previous));
}
}, [activityItems]);

if ((isLoading || !activityItems) && !cursor) {
return (
<Fragment>
<Typography.Title level={2}>Activity Stream</Typography.Title>
<LoadingSpinner />.
</Fragment>
);
}
if (
activityItems?.results === undefined ||
activityItems?.results.length === 0
) {
return (
<Fragment>
<Typography.Title level={2}>Activity Stream</Typography.Title>
<div className="w-1/2 justify-center">
<Paper border={true}>
<ul role="list" className="divide-y divide-gray-200">
{activityItems?.results.map((activityItem) => (
<li key={activityItem.id} className="py-4">
<div className="flex space-x-3">
<div className="flex-1 space-y-3">
<div className="flex items-center justify-between">
<h3 className="font-bold">
User<b> {activityItem.actor.string_repr}</b>
</h3>
<h3 className=" text-gray-500">
{dayjs(activityItem.timestamp).format(
"YYYY/MM/DD HH:mm:ss"
)}
</h3>
</div>
<h3 className="m">
{activityItem.verb}{" "}
<b>{activityItem.action_object.string_repr}</b> (
{activityItem.action_object.object_type})
{activityItem?.target ? (
<h3 className="mt-1">
on <b>{activityItem.target.string_repr}</b> (
{activityItem?.target.object_type})
</h3>
) : (
""
)}{" "}
</h3>
</div>
</div>
</li>
))}
</ul>
</Paper>
<Fragment>
<Typography.Title level={2}>Activity Stream</Typography.Title>
<div className="align-center">
<h3 className="text-xl font-main align-center">No Activities</h3>
<div className="separator mb-5 mt-5" />
</div>
</Fragment>
);
}

const handleMovements = (direction: "LEFT" | "RIGHT" | "START") => {
switch (direction) {
case "LEFT":
if (currentPage == 1) return;
setCursor(previous);
setCurrentPage(currentPage - 1);
queryClient.invalidateQueries(["preview_events", cursor]);
return;
case "RIGHT":
setCursor(next);
setCurrentPage(currentPage + 1);
queryClient.invalidateQueries(["preview_events", cursor]);
return;
case "START":
setCursor(null);
setCurrentPage(1);
queryClient.invalidateQueries(["preview_events", null]);
return;
}
};

{(!activityItems && !!cursor) && (
<div className="loadMoreSpinner">
<LoadingSpinner />.
return (
<Fragment>
<Typography.Title level={2}>Activity Stream</Typography.Title>
<div className="w-1/2 justify-center">
<Paper border={true}>
<ul role="list" className="divide-y divide-gray-200">
{activityItems?.results.map((activityItem) => (
<li key={activityItem.id} className="py-4">
<div className="flex space-x-3">
<div className="flex-1 space-y-3">
<div className="flex items-center justify-between">
<h3 className="font-bold">
User<b> {activityItem.actor.string_repr}</b>
</h3>
<h3 className=" text-gray-500">
{dayjs(activityItem.timestamp).format(
"YYYY/MM/DD HH:mm:ss"
)}
</h3>
</div>
)}
<h3 className="m">
{activityItem.verb}{" "}
<b>{activityItem.action_object.string_repr}</b> (
{activityItem.action_object.object_type})
{activityItem?.target ? (
<h3 className="mt-1">
on <b>{activityItem.target.string_repr}</b> (
{activityItem?.target.object_type})
</h3>
) : (
""
)}{" "}
</h3>
</div>
</div>
</li>
))}
</ul>
</Paper>

<div className="separator mb-5 mt-5"/>
{!activityItems && !!cursor && (
<div className="loadMoreSpinner">
<LoadingSpinner />.
</div>
)}

<CustomPagination cursor={cursor}
previous={previous}
next={next}
currentPage={currentPage}
handleMovements={handleMovements}
/>
</div>
</Fragment>
);
<div className="separator mb-5 mt-5" />

<CustomPagination
cursor={cursor}
previous={previous}
next={next}
currentPage={currentPage}
handleMovements={handleMovements}
/>
</div>
</Fragment>
);
}
22 changes: 11 additions & 11 deletions frontend/src/components/Settings/settings/tabs/IntegrationsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ import { AppCard } from "../components/AppCard";
const IntegrationsTab: FC = () => {
const navigate = useNavigate();
const [connectedStatus, setConnectedStatus] = useState<boolean>(false);
const fetchPaymentProcessorConnect = async (): Promise<
PaymentProcessorStatusType[]
> =>
PaymentProcessorIntegration.getPaymentProcessorConnectionStatus().then(
(data) => {
return data;
}
);
const { status, error, data, isLoading } = useQuery<
PaymentProcessorStatusType[]
>(["PaymentProcessorIntegration"], fetchPaymentProcessorConnect);
const { data, isLoading } = useQuery<PaymentProcessorStatusType[]>(
["PaymentProcessorIntegration"],
() =>
PaymentProcessorIntegration.getPaymentProcessorConnectionStatus().then(
(res) => {
return res;
}
)
);

const handleConnectWithPaymentProcessorClick = (path: string) => {
if (path !== "") {
window.location.href = path;
Expand All @@ -32,6 +31,7 @@ const IntegrationsTab: FC = () => {
<Typography.Title level={2}>Integrations</Typography.Title>
<Row gutter={[24, 24]}>
{data &&
data !== undefined &&
data.map((item, index) => {
return (
<Col span={6} key={index}>
Expand Down

0 comments on commit 7b4ecfc

Please sign in to comment.