Skip to content

Commit 40c29a0

Browse files
authored
Merge pull request #150 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 8259aa9 + f5ca02c commit 40c29a0

File tree

3 files changed

+84
-6
lines changed

3 files changed

+84
-6
lines changed

src/components/CippComponents/CippAutocomplete.jsx

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export const CippAutoComplete = (props) => {
6969
isFetching = false,
7070
sx,
7171
removeOptions = [],
72+
sortOptions = false,
7273
...other
7374
} = props;
7475

@@ -178,6 +179,9 @@ export const CippAutoComplete = (props) => {
178179
if (removeOptions && removeOptions.length) {
179180
finalOptions = finalOptions.filter((o) => !removeOptions.includes(o.value));
180181
}
182+
if (sortOptions) {
183+
finalOptions.sort((a, b) => a.label?.localeCompare(b.label));
184+
}
181185
return finalOptions;
182186
}, [api, usedOptions, options, removeOptions]);
183187

src/pages/tenant/administration/add-subscription/index.jsx

+65-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import React from "react";
2-
import { Box, Divider, Grid } from "@mui/material";
2+
import { Box, Typography } from "@mui/material";
33
import CippFormPage from "/src/components/CippFormPages/CippFormPage";
44
import { Layout as DashboardLayout } from "/src/layouts/index.js";
5-
import { useForm } from "react-hook-form";
5+
import { useForm, useWatch } from "react-hook-form";
66
import CippFormComponent from "/src/components/CippComponents/CippFormComponent";
77
import { useSettings } from "/src/hooks/use-settings";
8-
import { darken, lighten, styled } from "@mui/system";
8+
import { Grid, darken, lighten, styled } from "@mui/system";
9+
import { CippPropertyList } from "/src/components/CippComponents/CippPropertyList";
10+
import { CippPropertyListCard } from "../../../../components/CippCards/CippPropertyListCard";
11+
import { getCippFormatting } from "../../../../utils/get-cipp-formatting";
12+
import { getCippTranslation } from "../../../../utils/get-cipp-translation";
913

1014
const Page = () => {
1115
const userSettingsDefaults = useSettings();
@@ -19,6 +23,12 @@ const Page = () => {
1923
iagree: false,
2024
},
2125
});
26+
27+
const selectedSku = useWatch({
28+
control: formControl.control,
29+
name: "sku",
30+
});
31+
2232
const GroupHeader = styled("div")(({ theme }) => ({
2333
position: "sticky",
2434
top: "-8px",
@@ -46,7 +56,7 @@ const Page = () => {
4656
<Box sx={{ my: 2 }}>
4757
<Grid container spacing={2}>
4858
{/* Conditional Access Policy Selector */}
49-
<Grid item xs={6}>
59+
<Grid size={{ xs: 6 }}>
5060
<CippFormComponent
5161
type="autoComplete"
5262
creatable={false}
@@ -57,20 +67,69 @@ const Page = () => {
5767
url: "/api/ListCSPsku",
5868
labelField: (option) => `${option?.name[0]?.value} (${option?.sku})`,
5969
valueField: "sku",
70+
71+
addedField: {
72+
billingCycle: "billingCycle",
73+
commitmentTerm: "commitmentTerm",
74+
description: "description",
75+
},
6076
}}
6177
multiple={false}
6278
formControl={formControl}
79+
required={true}
80+
validators={{
81+
validate: (option) => {
82+
return option?.value ? true : "This field is required.";
83+
},
84+
}}
85+
sortOptions={true}
6386
/>
6487
</Grid>
65-
<Grid item xs={6}>
88+
<Grid size={{ xs: 6 }}>
6689
<CippFormComponent
6790
type="number"
6891
label="Quantity of licenses to purchase."
6992
name="Quantity"
7093
formControl={formControl}
94+
validators={{
95+
required: "This field is required.",
96+
min: {
97+
value: 1,
98+
message: "Minimum value is 1.",
99+
},
100+
}}
101+
required={true}
71102
/>
72103
</Grid>
73-
<Grid item xs={12}>
104+
{selectedSku?.value && (
105+
<Grid size={{ xs: 12 }}>
106+
{console.log(selectedSku)}
107+
<CippPropertyListCard
108+
title="Selected SKU Details"
109+
variant="outlined"
110+
showDivider={false}
111+
propertyItems={[
112+
{ label: "Name", value: selectedSku?.label },
113+
{
114+
label: "Billing Cycle",
115+
value: getCippTranslation(selectedSku?.addedFields?.billingCycle),
116+
},
117+
{
118+
label: "Commitment Term",
119+
value: getCippTranslation(selectedSku?.addedFields?.commitmentTerm),
120+
},
121+
{
122+
label: "Description",
123+
value: getCippFormatting(
124+
selectedSku?.addedFields?.description?.[0]?.value,
125+
"htmlDescription"
126+
),
127+
},
128+
]}
129+
/>
130+
</Grid>
131+
)}
132+
<Grid size={{ xs: 12 }}>
74133
<CippFormComponent
75134
type="checkbox"
76135
label="I understand that buy pressing submit this license will be purchased according to the terms and conditions for this SKU with Sherweb."

src/utils/get-cipp-formatting.js

+15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { CippTimeAgo } from "../components/CippComponents/CippTimeAgo";
1919
import { getCippRoleTranslation } from "./get-cipp-role-translation";
2020
import { CogIcon, ServerIcon, UserIcon, UsersIcon } from "@heroicons/react/24/outline";
2121
import { getCippTranslation } from "./get-cipp-translation";
22+
import DOMPurify from "dompurify";
2223
import { getSignInErrorCodeTranslation } from "./get-cipp-signin-errorcode-translation";
2324

2425
export const getCippFormatting = (data, cellName, type, canReceive) => {
@@ -432,6 +433,20 @@ export const getCippFormatting = (data, cellName, type, canReceive) => {
432433
);
433434
}
434435

436+
// handle htmlDescription
437+
if (cellName === "htmlDescription") {
438+
return isText ? (
439+
data
440+
) : (
441+
<Box
442+
component="span"
443+
dangerouslySetInnerHTML={{
444+
__html: DOMPurify.sanitize(data),
445+
}}
446+
/>
447+
);
448+
}
449+
435450
const durationArray = ["autoExtendDuration"];
436451
if (durationArray.includes(cellName)) {
437452
isoDuration.setLocales(

0 commit comments

Comments
 (0)