Skip to content

Commit

Permalink
fix(admin): Color enabled checkbox wasn't applied properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsvante committed May 10, 2023
1 parent 4a94ec3 commit fe0b4b9
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 167 deletions.
15 changes: 3 additions & 12 deletions ui/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ interface ApiSurface {
fetchPriceLists: (
token: string,
organizationId: number,
collectionSlug?: string | null,
) => Promise<Result<PriceListSummary[], ApiErrorResponse>>;
fetchCategories: (
token: string,
Expand Down Expand Up @@ -417,15 +416,10 @@ function makeApi(baseUrl: string): ApiSurface {
async fetchPriceLists(
token: string,
organizationId: number,
collectionSlug?: string | null,
): Promise<Result<PriceListSummary[], ApiErrorResponse>> {
let filters = {};
if (!!collectionSlug) {
Object.assign(filters, { collection: { slug: collectionSlug } });
}
return await getJson<PriceListSummary[]>(
`/${organizationId}/pricelists/summary`,
{ token, filters },
{ token },
);
},
async fetchCategories(
Expand Down Expand Up @@ -852,9 +846,7 @@ type PricelistsFetchResult = Result<
ApiErrorResponse
>;

export function usePricelists(
collectionSlug?: string | null,
): PricelistsFetchResult {
export function usePricelists(): PricelistsFetchResult {
const { token, activeOrganization } = useAppSelector((state) => state.user);
const [fetchResult, setFetchResult] = useState(
Ok(null) as PricelistsFetchResult,
Expand All @@ -866,13 +858,12 @@ export function usePricelists(
.fetchPriceLists(
token as string,
activeOrganization.organization.id,
collectionSlug,
)
.then((result) => {
setFetchResult(result);
});
}
}, [token, activeOrganization, collectionSlug]);
}, [token, activeOrganization]);

return fetchResult;
}
Expand Down
15 changes: 6 additions & 9 deletions ui/src/components/admin/AddCollectionItemsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import {
import { useNestedStyles } from "../../api";
import { useLocalize } from "../../i18n";
import { cloudflareImageUrl } from "../../images";
import { EditableStyle, makeEditableStyle } from "../../types/admin";
import { EditableStyle, makeEditableStyle, transferIsNew } from "../../types/admin";
import {
EntityFilterChoice,
ItemFilterChoices,
NestedStyle,
NestedStyleSummary,
StyleFilters,
} from "../../types/api";
Expand All @@ -27,14 +26,12 @@ type ItemStatus = string;
export default function AddCollectionItemsModal({
open,
setOpen,
collectionStylesMap,
allNestedStylesMap,
setEditableStyles,
itemFilterChoices,
}: {
open: boolean;
setOpen: Dispatch<SetStateAction<boolean>>;
collectionStylesMap: Map<number, NestedStyle>;
allNestedStylesMap: Map<number, NestedStyleSummary>;
setEditableStyles: Dispatch<SetStateAction<EditableStyle[]>>;
itemFilterChoices: ItemFilterChoices;
Expand All @@ -44,7 +41,6 @@ export default function AddCollectionItemsModal({
const [filters, setFilters] = useState(() => ({} as StyleFilters));
const [nestedStylesResult] = useNestedStyles(filters);
const nestedStyles = nestedStylesResult.unwrapOr([]) || [];

// Status filter
const [filteredStatuses, setFilteredStatuses] = useState(
() => [] as ItemStatus[],
Expand Down Expand Up @@ -93,15 +89,15 @@ export default function AddCollectionItemsModal({
prevEditableStyles.map((style, idx) => [style.id, idx]),
);
const newEditableStyles = nestedStyles.flatMap((nestedStyle) => {
const style = collectionStylesMap.get(nestedStyle.id);
const fullStyle = allNestedStylesMap.get(nestedStyle.id);
if (fullStyle) {
const newStyle = makeEditableStyle(style || fullStyle, fullStyle);
const newStyle = makeEditableStyle(nestedStyle || fullStyle, fullStyle);
const prevIdx = prevMapIndexes.get(nestedStyle.id);
if (prevIdx === undefined) {
return [newStyle];
} else {
prevEditableStyles[prevIdx] = newStyle;
const prevStyle = prevEditableStyles[prevIdx];
prevEditableStyles[prevIdx] = transferIsNew(prevStyle, newStyle);
return [];
}
} else {
Expand Down Expand Up @@ -168,6 +164,7 @@ export default function AddCollectionItemsModal({
<div className="my-5">
<MultipleCombobox
title={t`Status`}
description={t`This filter is applied at the size level which means that it will affect which colors/sizes are selected for each style.`}
allItems={itemFilterChoices.status}
selectedItems={filteredStatuses}
setSelectedItems={setFilteredStatuses}
Expand All @@ -193,7 +190,7 @@ export default function AddCollectionItemsModal({
<div className="my-5">
<MultipleCombobox
title={t`Attributes`}
description={`Different types of attributes must all get matched. Within the same type any may match.`}
description={t`Different types of attributes must all get matched. Within the same type any may match.`}
allItems={itemFilterChoices.attribute}
selectedItems={filteredAttributes}
setSelectedItems={setFilteredAttributes}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/locales/en/messages.js

Large diffs are not rendered by default.

Loading

0 comments on commit fe0b4b9

Please sign in to comment.