Skip to content
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

Use target endpoints for Service Catalog list and item #544

Open
wants to merge 1 commit into
base: service-catalog-eap
Choose a base branch
from
Open
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
127 changes: 73 additions & 54 deletions assets/service-catalog-bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 26 additions & 61 deletions src/modules/service-catalog/ServiceCatalogItemPage.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
import { XXXL } from "@zendeskgarden/react-typography";
import type { ServiceCatalogItem } from "./data-types/ServiceCatalogItem";
import styled from "styled-components";
import { Button } from "@zendeskgarden/react-buttons";
import { useState } from "react";
import ChevronUp from "@zendeskgarden/svg-icons/src/16/chevron-up-fill.svg";
import ChevronDown from "@zendeskgarden/svg-icons/src/16/chevron-down-fill.svg";
import { useEffect, useState } from "react";
import { getColorV8 } from "@zendeskgarden/react-theming";
import { useTranslation } from "react-i18next";
import { useItemFormFields } from "./components/useItemFormFields";
import { ItemRequestForm } from "./components/service-catalog-item/ItemRequestForm";
import type { Organization } from "../ticket-fields";
import { CollapsibleDescription } from "./components/service-catalog-item/CollapsibleDescription";

const ItemTitle = styled(XXXL)`
font-weight: ${(props) => props.theme.fontWeights.semibold};
`;

const CollapsibleDescription = styled.div<{ expanded: boolean }>`
font-size: ${(props) => props.theme.fontSizes.md};
text-align: left;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: ${(props) => (props.expanded ? "none" : 3)};
overflow: hidden;
margin-top: ${(props) => props.theme.space.md};
padding-right: ${(props) => props.theme.space.xl};

@media (max-width: ${(props) => props.theme.breakpoints.md}) {
padding-right: 0;
}
`;
const Container = styled.div`
display: flex;
flex-direction: row;
Expand All @@ -52,17 +32,6 @@ const LeftColumn = styled.div`
}
`;

const DescriptionWrapper = styled.div`
border-bottom: ${(props) => props.theme.borders.sm}
${(props) => getColorV8("grey", 300, props.theme)};
padding-bottom: ${(props) => props.theme.space.lg};
margin-right: ${(props) => props.theme.space.xl};

@media (max-width: ${(props) => props.theme.breakpoints.md}) {
margin-right: 0;
}
`;

const FromFieldsWrapper = styled.div`
margin-right: ${(props) => props.theme.space.xl};

Expand All @@ -86,14 +55,6 @@ const RightColumn = styled.div`
}
`;

const ToggleButton = styled(Button)`
margin-top: ${(props) => props.theme.space.sm};
font-size: ${(props) => props.theme.fontSizes.md};
&:hover {
text-decoration: none;
}
`;

const ButtonWrapper = styled.div`
padding: ${(props) => props.theme.space.lg};
border: ${(props) => props.theme.borders.sm}
Expand All @@ -117,7 +78,7 @@ const ButtonWrapper = styled.div`
`;

export interface ServiceCatalogItemPageProps {
serviceCatalogItem: ServiceCatalogItem;
serviceCatalogItemId: number;
baseLocale: string;
hasAtMentions: boolean;
userRole: string;
Expand All @@ -128,15 +89,16 @@ export interface ServiceCatalogItemPageProps {
}

export function ServiceCatalogItemPage({
serviceCatalogItem,
serviceCatalogItemId,
baseLocale,
hasAtMentions,
userRole,
organizations,
userId,
brandId,
}: ServiceCatalogItemPageProps) {
const [isExpanded, setIsExpanded] = useState<boolean>(false);
const [serviceCatalogItem, setServiceCatalogItem] =
useState<ServiceCatalogItem>({} as ServiceCatalogItem);
const { requestFields, handleChange } = useItemFormFields(
serviceCatalogItem,
baseLocale
Expand All @@ -147,27 +109,30 @@ export function ServiceCatalogItemPage({
? organizations[0]?.id?.toString()
: null;

const toggleDescription = () => {
setIsExpanded(!isExpanded);
};
useEffect(() => {
async function fetchServiceCatalogItem() {
try {
const response = await fetch(
`/api/v2/help_center/service_catalog/items/${serviceCatalogItemId}`
);
const data = await response.json();
if (response.ok) {
setServiceCatalogItem(data.service_catalog_item);
}
} catch (error) {
console.error("Error fetching service catalog item:", error);
}
}
fetchServiceCatalogItem();
}, [serviceCatalogItemId]);

return (
<Container>
<LeftColumn>
<DescriptionWrapper>
<ItemTitle tag="h1">{serviceCatalogItem.name}</ItemTitle>
<CollapsibleDescription expanded={isExpanded}>
{serviceCatalogItem.description}
</CollapsibleDescription>
<ToggleButton isLink onClick={toggleDescription}>
{isExpanded
? t("service-catalog.item.read-less", "Read less")
: t("service-catalog.item.read-more", "Read more")}
<Button.EndIcon>
{isExpanded ? <ChevronUp /> : <ChevronDown />}
</Button.EndIcon>
</ToggleButton>
</DescriptionWrapper>
<CollapsibleDescription
title={serviceCatalogItem.name}
description={serviceCatalogItem.description}
/>
<FromFieldsWrapper>
<ItemRequestForm
requestFields={requestFields}
Expand Down
25 changes: 3 additions & 22 deletions src/modules/service-catalog/ServiceCatalogList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,13 @@ export function ServiceCatalogList({
try {
const response = await fetch(
currentCursor
? `/api/v2/custom_objects/service_catalog_item/records?page[size]=16&${currentCursor}`
: `/api/v2/custom_objects/service_catalog_item/records?page[size]=16`
? `/api/v2/help_center/service_catalog/items?page[size]=16&${currentCursor}`
: `/api/v2/help_center/service_catalog/items?page[size]=16`
);
const data = await response.json();
if (response.ok) {
const records = data.custom_object_records.map(
({
id,
name,
custom_object_fields,
custom_object_key,
}: {
id: number;
name: string;
custom_object_fields: { description: string; form_id: string };
custom_object_key: string;
}) => ({
id,
name,
description: custom_object_fields.description,
form_id: custom_object_fields.form_id,
custom_object_key,
})
);
setMeta(data.meta);
setServiceCatalogItems(records);
setServiceCatalogItems(data.service_catalog_items);
setIsLoading(false);
}
} catch (error) {
Expand Down
Loading
Loading