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

fix(dashboard,types): Fix TS errors #10457

Merged
merged 1 commit into from
Dec 8, 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
6 changes: 6 additions & 0 deletions .changeset/stale-eyes-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/dashboard": patch
"@medusajs/types": patch
---

fix(dashboard,types): Fix TS errors
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DropdownMenu, IconButton, clx } from "@medusajs/ui"

import { EllipsisHorizontal } from "@medusajs/icons"
import { ReactNode } from "react"
import { PropsWithChildren, ReactNode } from "react"
import { Link } from "react-router-dom"
import { ConditionalTooltip } from "../conditional-tooltip"

Expand All @@ -28,18 +28,20 @@ export type ActionGroup = {
actions: Action[]
}

type ActionMenuProps = {
type ActionMenuProps = PropsWithChildren<{
groups: ActionGroup[]
}
}>

export const ActionMenu = ({ groups, children }: ActionMenuProps) => {
const inner = children ?? (
<IconButton size="small" variant="transparent">
<EllipsisHorizontal />
</IconButton>
)

export const ActionMenu = ({ groups }: ActionMenuProps) => {
return (
<DropdownMenu>
<DropdownMenu.Trigger asChild>
<IconButton size="small" variant="transparent">
<EllipsisHorizontal />
</IconButton>
</DropdownMenu.Trigger>
<DropdownMenu.Trigger asChild>{inner}</DropdownMenu.Trigger>
<DropdownMenu.Content>
{groups.map((group, index) => {
if (!group.actions.length) {
Expand Down

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions packages/admin/dashboard/src/components/common/date/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { Heading, Input, Select, clx } from "@medusajs/ui"
import { useTranslation } from "react-i18next"
import { z } from "zod"

import { HttpTypes } from "@medusajs/types"
import { Control } from "react-hook-form"
import { AddressSchema } from "../../../lib/schemas"
import { Form } from "../../common/form"
import { CountrySelect } from "../../inputs/country-select"
import { HttpTypes } from "@medusajs/types"

type AddressFieldValues = z.infer<typeof AddressSchema>

Expand Down Expand Up @@ -187,14 +187,24 @@ export const AddressForm = ({
<Select.Value />
</Select.Trigger>
<Select.Content>
{countries.map((country) => (
<Select.Item
key={country.iso_2}
value={country.iso_2}
>
{country.display_name}
</Select.Item>
))}
{countries.map((country) => {
/**
* If a country does not have an ISO 2 code, it is not
* a valid country and should not be selectable.
*/
if (!country.iso_2) {
return null
}

return (
<Select.Item
key={country.iso_2}
value={country.iso_2}
>
{country.display_name}
</Select.Item>
)
})}
</Select.Content>
</Select>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
Trash,
} from "@medusajs/icons"
import { FetchError } from "@medusajs/js-sdk"
import { ComponentPropsWithoutRef, forwardRef, useRef } from "react"
import { ComponentPropsWithoutRef, forwardRef } from "react"
import { ConditionalTooltip } from "../../common/conditional-tooltip"
import { Form } from "../../common/form"
import { InlineTip } from "../../common/inline-tip"
Expand Down Expand Up @@ -78,7 +78,6 @@ const InnerForm = <TRes,>({
const { t } = useTranslation()
const { handleSuccess } = useRouteModal()

const deletedOriginalRows = useRef<string[]>([])
const hasUneditableRows = getHasUneditableRows(metadata)

const form = useForm<z.infer<typeof MetadataSchema>>({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
import { Tooltip } from "@medusajs/ui"
import format from "date-fns/format"
import { useTranslation } from "react-i18next"
import { useDate } from "../../../../../hooks/use-date"
import { PlaceholderCell } from "../placeholder-cell"

type DateCellProps = {
date: Date | string | undefined
}

export const CreatedAtCell = ({ date }: DateCellProps) => {
const { getFullDate } = useDate()

if (!date) {
return <PlaceholderCell />
}

const value = new Date(date)
value.setMinutes(value.getMinutes() - value.getTimezoneOffset())

const hour12 = Intl.DateTimeFormat().resolvedOptions().hour12
const timestampFormat = hour12 ? "dd MMM yyyy hh:MM a" : "dd MMM yyyy HH:MM"

return (
<div className="flex h-full w-full items-center overflow-hidden">
<Tooltip
className="z-10"
content={
<span className="text-pretty">{`${format(
value,
timestampFormat
)}`}</span>
<span className="text-pretty">{`${getFullDate({
date,
includeTime: true,
})}`}</span>
}
>
<span className="truncate">{format(value, "dd MMM yyyy")}</span>
<span className="truncate">
{getFullDate({ date, includeTime: true })}
</span>
</Tooltip>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useTranslation } from "react-i18next"
export const CustomerCell = ({
customer,
}: {
customer: HttpTypes.AdminCustomer | null
customer?: HttpTypes.AdminCustomer | null
}) => {
if (!customer) {
return <span className="text-ui-fg-muted">-</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { HttpTypes } from "@medusajs/types"
import { useTranslation } from "react-i18next"
import { getOrderPaymentStatus } from "../../../../../lib/order-helpers"
import { StatusCell } from "../../common/status-cell"

type PaymentStatusCellProps = {
status: PaymentStatus
status: HttpTypes.AdminOrder["payment_status"]
}

export const PaymentStatusCell = ({ status }: PaymentStatusCellProps) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useTranslation } from "react-i18next"
export const SalesChannelCell = ({
channel,
}: {
channel: HttpTypes.AdminSalesChannel | null
channel?: HttpTypes.AdminSalesChannel | null
}) => {
if (!channel) {
return <span className="text-ui-fg-muted">-</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { RegionCountryDTO } from "@medusajs/types"
import { HttpTypes } from "@medusajs/types"
import { useTranslation } from "react-i18next"

import { countries as COUNTRIES } from "../../../../../lib/data/countries"
import { ListSummary } from "../../../../common/list-summary"
import { PlaceholderCell } from "../../common/placeholder-cell"

type CountriesCellProps = {
countries?: RegionCountryDTO[] | null
countries?: HttpTypes.AdminRegionCountry[] | null
}

export const CountriesCell = ({ countries }: CountriesCellProps) => {
const { t } = useTranslation()

if (!countries || countries.length === 0) {
return <PlaceholderCell />
}

const list = countries
.map(
(country) =>
COUNTRIES.find((c) => c.iso_2 === country.iso_2)?.display_name
)
.filter(Boolean) as string[]

return (
<div className="flex size-full items-center overflow-hidden">
<ListSummary
list={countries.map(
(country) =>
COUNTRIES.find((c) => c.iso_2 === country.iso_2)!.display_name
)}
/>
<ListSummary list={list} />
</div>
)
}
Expand Down

This file was deleted.

9 changes: 6 additions & 3 deletions packages/admin/dashboard/src/hooks/api/auth.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { UseMutationOptions, useMutation } from "@tanstack/react-query"
import { FetchError } from "@medusajs/js-sdk"
import { sdk } from "../../lib/client"
import { HttpTypes } from "@medusajs/types"
import { UseMutationOptions, useMutation } from "@tanstack/react-query"
import { sdk } from "../../lib/client"

export const useSignInWithEmailPass = (
options?: UseMutationOptions<
string,
| string
| {
location: string
},
FetchError,
HttpTypes.AdminSignUpWithEmailPassword
>
Expand Down
Loading
Loading