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

feat(dashboard): Pub Api Key domain #6162

Merged
merged 14 commits into from
Jan 23, 2024
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
5 changes: 5 additions & 0 deletions .changeset/gentle-pots-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/ui": patch
---

feature(ui): Adds a `size` variant to `<Copy />` component, and prevent clicks from propigating to parent elements". Also adds additional sizes to the `<Avatar />` component.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"details": "Details",
"enabled": "Enabled",
"disabled": "Disabled",
"active": "Active",
"revoked": "Revoked",
"remove": "Remove",
"admin": "Admin",
"store": "Store",
Expand Down Expand Up @@ -183,10 +185,16 @@
"domain": "API Key Management",
"createKey": "Create key",
"createPublishableApiKey": "Create Publishable API Key",
"editKey": "Edit key",
"revoke": "Revoke",
"publishableApiKeyHint": "Publishable API keys are used to limit the scope of requests to specific sales channels.",
"deleteKeyWarning": "You are about to delete the API key {{title}}. This action cannot be undone.",
"revokeKeyWarning": "You are about to revoke the API key {{title}}."
"revokeKeyWarning": "You are about to revoke the API key {{title}}. This action cannot be undone, and the key cannot be used in future requests.",
"removeSalesChannelWarning": "You are about to remove the sales channel {{name}} from the API key. This action cannot be undone.",
"removeSalesChannelsWarning_one": "You are about to remove {{count}} sales channel from the API key. This action cannot be undone.",
"removeSalesChannelsWarning_other": "You are about to remove {{count}} sales channels from the API key. This action cannot be undone.",
"createdBy": "Created by",
"revokedBy": "Revoked by"
},
"fields": {
"name": "Name",
Expand Down Expand Up @@ -234,6 +242,8 @@
"variants": "Variants",
"orders": "Orders",
"account": "Account",
"total": "Total"
"total": "Total",
"created": "Created",
"key": "Key"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./user-link"
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Avatar, Text } from "@medusajs/ui"
import { Link } from "react-router-dom"

type UserLinkProps = {
id: string
first_name?: string | null
last_name?: string | null
email: string
type?: "customer" | "user"
}

export const UserLink = ({
id,
first_name,
last_name,
email,
type = "user",
}: UserLinkProps) => {
const name = [first_name, last_name].filter(Boolean).join(" ")
const fallback = name ? name.slice(0, 1) : email.slice(0, 1)
const link = type === "user" ? `/settings/users/${id}` : `/customers/${id}`

return (
<Link
to={link}
className="flex items-center gap-x-2 w-fit transition-fg hover:text-ui-fg-subtle outline-none focus-visible:shadow-borders-focus rounded-md"
>
<Avatar size="2xsmall" fallback={fallback.toUpperCase()} />
<Text size="small" leading="compact" weight="regular">
{name || email}
</Text>
</Link>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import type {
AdminCustomerGroupsRes,
AdminCustomersRes,
AdminProductsRes,
AdminPublishableApiKeysRes,
AdminRegionsRes,
AdminSalesChannelsRes,
} from "@medusajs/medusa"
import {
Outlet,
Expand Down Expand Up @@ -487,6 +489,10 @@ const router = createBrowserRouter([
path: ":id",
lazy: () =>
import("../../routes/sales-channels/sales-channel-detail"),
handle: {
crumb: (data: AdminSalesChannelsRes) =>
data.sales_channel.name,
},
children: [
{
path: "edit",
Expand Down Expand Up @@ -533,6 +539,10 @@ const router = createBrowserRouter([
import(
"../../routes/api-key-management/api-key-management-detail"
),
handle: {
crumb: (data: AdminPublishableApiKeysRes) =>
data.publishable_api_key.title,
},
children: [
{
path: "edit",
Expand All @@ -541,6 +551,13 @@ const router = createBrowserRouter([
"../../routes/api-key-management/api-key-management-edit"
),
},
{
path: "add-sales-channels",
lazy: () =>
import(
"../../routes/api-key-management/api-key-management-add-sales-channels"
),
},
],
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { FocusModal } from "@medusajs/ui"
import { useAdminPublishableApiKeySalesChannels } from "medusa-react"
import { useParams } from "react-router-dom"
import { useRouteModalState } from "../../../hooks/use-route-modal-state"
import { AddSalesChannelsToApiKeyForm } from "./components"

export const ApiKeyManagementAddSalesChannels = () => {
const { id } = useParams()
const [open, onOpenChange, subscribe] = useRouteModalState()

const { sales_channels, isLoading, isError, error } =
useAdminPublishableApiKeySalesChannels(id!)

const handleSuccessfulSubmit = () => {
onOpenChange(false, true)
}

if (isError) {
throw error
}

return (
<FocusModal open={open} onOpenChange={onOpenChange}>
<FocusModal.Content>
{!isLoading && sales_channels && (
<AddSalesChannelsToApiKeyForm
apiKey={id!}
preSelected={sales_channels.map((sc) => sc.id)}
onSuccessfulSubmit={handleSuccessfulSubmit}
subscribe={subscribe}
/>
)}
</FocusModal.Content>
</FocusModal>
)
}
Loading