Skip to content

feat(web): dynamic-values-in-cases-page #1137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions web/src/components/CasesDisplay/Stats.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import React from "react";
import styled from "styled-components";
import { useAllCasesQuery } from "hooks/queries/useAllCasesQuery";

const FieldWrapper = styled.div`
display: inline-flex;
gap: 8px;
`;

const Field: React.FC<{ label: string; value: string }> = ({
label,
value,
}) => (
const Field: React.FC<{ label: string; value: string }> = ({ label, value }) => (
<FieldWrapper>
<label>{label}</label>
<small>{value}</small>
Expand All @@ -23,21 +21,29 @@ const SeparatorLabel = styled.label`

const Separator: React.FC = () => <SeparatorLabel>|</SeparatorLabel>;

const fields = [
{ label: "Total", value: "600" },
{ label: "In Progress", value: "50" },
{ label: "Closed", value: "550" },
];

const Stats: React.FC = () => (
<div>
{fields.map(({ label, value }, i) => (
<React.Fragment key={i}>
<Field {...{ label, value }} />
{i + 1 < fields.length ? <Separator /> : null}
</React.Fragment>
))}
</div>
);
const Stats: React.FC = () => {
const { data } = useAllCasesQuery();

const totalDisputes = data?.counter?.cases;
const closedDisputes = data?.counter?.casesRuled;
const inProgressDisputes = (totalDisputes - closedDisputes).toString();

const fields = [
{ label: "Total", value: totalDisputes ?? "0" },
{ label: "In Progress", value: inProgressDisputes ?? "0" },
{ label: "Closed", value: closedDisputes ?? "0" },
];

return (
<div>
{fields.map(({ label, value }, i) => (
<React.Fragment key={i}>
<Field {...{ label, value }} />
{i + 1 < fields.length ? <Separator /> : null}
</React.Fragment>
))}
</div>
);
};

export default Stats;
21 changes: 21 additions & 0 deletions web/src/hooks/queries/useAllCasesQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { graphql } from "src/graphql";
import { useQuery } from "@tanstack/react-query";
import { AllCasesQuery } from "src/graphql/graphql";
import { graphqlQueryFnHelper } from "utils/graphqlQueryFnHelper";
export type { AllCasesQuery };

const allCasesQuery = graphql(`
query AllCases {
counter(id: 0) {
cases
casesRuled
}
}
`);

export const useAllCasesQuery = () => {
return useQuery({
queryKey: [`allCasesQuery`],
queryFn: async () => await graphqlQueryFnHelper(allCasesQuery, {}),
});
};