mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-19 23:35:26 +00:00
♻️ update
This commit is contained in:
@@ -40,6 +40,8 @@ import { orgQueries, resourceQueries } from "@app/lib/queries";
|
|||||||
import { ResourcePolicyProvider } from "@app/providers/ResourcePolicyProvider";
|
import { ResourcePolicyProvider } from "@app/providers/ResourcePolicyProvider";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { CaretSortIcon } from "@radix-ui/react-icons";
|
import { CaretSortIcon } from "@radix-ui/react-icons";
|
||||||
|
import { build } from "@server/build";
|
||||||
|
import { tierMatrix } from "@server/lib/billing/tierMatrix";
|
||||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import { ArrowRightIcon, CheckIcon, ShieldAlertIcon } from "lucide-react";
|
import { ArrowRightIcon, CheckIcon, ShieldAlertIcon } from "lucide-react";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
@@ -73,8 +75,6 @@ export default function ResourceAuthenticationPage() {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
|
|
||||||
const { isPaidUser } = usePaidStatus();
|
|
||||||
|
|
||||||
const { data: policies, isLoading: isLoadingPolicies } = useQuery(
|
const { data: policies, isLoading: isLoadingPolicies } = useQuery(
|
||||||
resourceQueries.policies({
|
resourceQueries.policies({
|
||||||
resourceId: resource.resourceId
|
resourceId: resource.resourceId
|
||||||
@@ -84,7 +84,10 @@ export default function ResourceAuthenticationPage() {
|
|||||||
const form = useForm({
|
const form = useForm({
|
||||||
resolver: zodResolver(resourceTypeSchema),
|
resolver: zodResolver(resourceTypeSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
type: resource.resourcePolicyId ? "shared" : "inline"
|
type:
|
||||||
|
build !== "oss" && resource.resourcePolicyId
|
||||||
|
? "shared"
|
||||||
|
: "inline"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -185,99 +188,112 @@ export default function ResourceAuthenticationPage() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SettingsContainer>
|
<SettingsContainer>
|
||||||
<SettingsSection>
|
{build !== "oss" && (
|
||||||
<SettingsSectionHeader>
|
<SettingsSection>
|
||||||
<SettingsSectionTitle>
|
<SettingsSectionHeader>
|
||||||
{t("resourcePolicySelectTitle")}
|
<SettingsSectionTitle>
|
||||||
</SettingsSectionTitle>
|
{t("resourcePolicySelectTitle")}
|
||||||
<SettingsSectionDescription>
|
</SettingsSectionTitle>
|
||||||
{t("resourcePolicySelectDescription")}
|
<SettingsSectionDescription>
|
||||||
</SettingsSectionDescription>
|
{t("resourcePolicySelectDescription")}
|
||||||
</SettingsSectionHeader>
|
</SettingsSectionDescription>
|
||||||
<SettingsSectionBody>
|
</SettingsSectionHeader>
|
||||||
<StrategySelect
|
<SettingsSectionBody>
|
||||||
options={resourcePolicyTypes}
|
<StrategySelect
|
||||||
value={selectedResourceType}
|
options={resourcePolicyTypes}
|
||||||
onChange={(value) => {
|
value={selectedResourceType}
|
||||||
form.setValue("type", value);
|
onChange={(value) => {
|
||||||
}}
|
form.setValue("type", value);
|
||||||
cols={2}
|
}}
|
||||||
/>
|
cols={2}
|
||||||
{selectedResourceType === "shared" && (
|
/>
|
||||||
<Popover>
|
{selectedResourceType === "shared" && (
|
||||||
<PopoverTrigger asChild>
|
<Popover>
|
||||||
<Button
|
<PopoverTrigger asChild>
|
||||||
variant="outline"
|
<Button
|
||||||
role="combobox"
|
variant="outline"
|
||||||
className={
|
role="combobox"
|
||||||
"w-full md:w-1/2 justify-between"
|
className={
|
||||||
}
|
"w-full md:w-1/2 justify-between"
|
||||||
>
|
|
||||||
<span className="truncate max-w-37.5">
|
|
||||||
{selectedPolicy
|
|
||||||
? selectedPolicy.name
|
|
||||||
: t("resourcePolicySelect")}
|
|
||||||
</span>
|
|
||||||
<CaretSortIcon className="ml-2h-4 w-4 shrink-0 opacity-50" />
|
|
||||||
</Button>
|
|
||||||
</PopoverTrigger>
|
|
||||||
<PopoverContent className="p-0 w-45">
|
|
||||||
<Command shouldFilter={false}>
|
|
||||||
<CommandInput
|
|
||||||
placeholder={t("siteSearch")}
|
|
||||||
value={resourcePolicysearchQuery}
|
|
||||||
onValueChange={
|
|
||||||
setResourcePolicySearchQuery
|
|
||||||
}
|
}
|
||||||
/>
|
>
|
||||||
<CommandList>
|
<span className="truncate max-w-37.5">
|
||||||
<CommandEmpty>
|
{selectedPolicy
|
||||||
{t("resourcePolicyNotFound")}
|
? selectedPolicy.name
|
||||||
</CommandEmpty>
|
: t("resourcePolicySelect")}
|
||||||
<CommandGroup>
|
</span>
|
||||||
{policiesList.map((policy) => (
|
<CaretSortIcon className="ml-2h-4 w-4 shrink-0 opacity-50" />
|
||||||
<CommandItem
|
</Button>
|
||||||
key={
|
</PopoverTrigger>
|
||||||
policy.resourcePolicyId
|
<PopoverContent className="p-0 w-45">
|
||||||
}
|
<Command shouldFilter={false}>
|
||||||
value={policy.resourcePolicyId.toString()}
|
<CommandInput
|
||||||
onSelect={() =>
|
placeholder={t("siteSearch")}
|
||||||
setSelectedPolicy({
|
value={
|
||||||
id: policy.resourcePolicyId,
|
resourcePolicysearchQuery
|
||||||
name: policy.name
|
}
|
||||||
})
|
onValueChange={
|
||||||
}
|
setResourcePolicySearchQuery
|
||||||
>
|
}
|
||||||
<CheckIcon
|
/>
|
||||||
className={cn(
|
<CommandList>
|
||||||
"mr-2 h-4 w-4",
|
<CommandEmpty>
|
||||||
policy.resourcePolicyId ===
|
{t(
|
||||||
selectedPolicy?.id
|
"resourcePolicyNotFound"
|
||||||
? "opacity-100"
|
)}
|
||||||
: "opacity-0"
|
</CommandEmpty>
|
||||||
)}
|
<CommandGroup>
|
||||||
/>
|
{policiesList.map(
|
||||||
{policy.name}
|
(policy) => (
|
||||||
</CommandItem>
|
<CommandItem
|
||||||
))}
|
key={
|
||||||
</CommandGroup>
|
policy.resourcePolicyId
|
||||||
</CommandList>
|
}
|
||||||
</Command>
|
value={policy.resourcePolicyId.toString()}
|
||||||
</PopoverContent>
|
onSelect={() =>
|
||||||
</Popover>
|
setSelectedPolicy(
|
||||||
)}
|
{
|
||||||
</SettingsSectionBody>
|
id: policy.resourcePolicyId,
|
||||||
<SettingsSectionFooter className="justify-start">
|
name: policy.name
|
||||||
<Button
|
}
|
||||||
onClick={() =>
|
)
|
||||||
startTransition(handleSaveResourcePolicyType)
|
}
|
||||||
}
|
>
|
||||||
loading={isUpdatingResource}
|
<CheckIcon
|
||||||
>
|
className={cn(
|
||||||
{t("resourcePolicyTypeSave")}
|
"mr-2 h-4 w-4",
|
||||||
</Button>
|
policy.resourcePolicyId ===
|
||||||
</SettingsSectionFooter>
|
selectedPolicy?.id
|
||||||
</SettingsSection>
|
? "opacity-100"
|
||||||
|
: "opacity-0"
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{policy.name}
|
||||||
|
</CommandItem>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</CommandGroup>
|
||||||
|
</CommandList>
|
||||||
|
</Command>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
)}
|
||||||
|
</SettingsSectionBody>
|
||||||
|
<SettingsSectionFooter className="justify-start">
|
||||||
|
<Button
|
||||||
|
onClick={() =>
|
||||||
|
startTransition(
|
||||||
|
handleSaveResourcePolicyType
|
||||||
|
)
|
||||||
|
}
|
||||||
|
loading={isUpdatingResource}
|
||||||
|
>
|
||||||
|
{t("resourcePolicyTypeSave")}
|
||||||
|
</Button>
|
||||||
|
</SettingsSectionFooter>
|
||||||
|
</SettingsSection>
|
||||||
|
)}
|
||||||
|
|
||||||
{selectedResourceType === "inline" ? (
|
{selectedResourceType === "inline" ? (
|
||||||
<ResourcePolicyProvider policy={policies.defaultPolicy}>
|
<ResourcePolicyProvider policy={policies.defaultPolicy}>
|
||||||
<EditPolicyForm hidePolicyNameForm />
|
<EditPolicyForm hidePolicyNameForm />
|
||||||
|
|||||||
Reference in New Issue
Block a user