fix(admin-ui): Lint all UI files (#3459)
This commit is contained in:
committed by
GitHub
parent
55febef7f1
commit
ad7d7fcd51
@@ -2,7 +2,7 @@ const units: [string, number][] = [
|
||||
["B", 1],
|
||||
["Kb", 1000],
|
||||
["Mb", 1000000],
|
||||
["Gb", 1000000000]
|
||||
["Gb", 1000000000],
|
||||
]
|
||||
|
||||
export function bytesConverter(size: number): string | undefined {
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
export const callAll = (...fns: Function[]) => (...args) =>
|
||||
fns?.forEach(async fn => typeof fn === "function" && fn(...args))
|
||||
export const callAll =
|
||||
(...fns: Function[]) =>
|
||||
(...args) =>
|
||||
fns?.forEach(async (fn) => typeof fn === "function" && fn(...args))
|
||||
|
||||
@@ -3,7 +3,7 @@ import { countryLookup } from "./countries"
|
||||
/**
|
||||
* Formats a shipping or billing address using the postal code, city, province, and country name
|
||||
* @param shippingOrBillingAddress
|
||||
* @returns {string} Returns a formatted string of the address
|
||||
* @return {string} Returns a formatted string of the address
|
||||
*/
|
||||
const formatAddress = (shippingOrBillingAddress) => {
|
||||
const postalCode = shippingOrBillingAddress.postal_code || ""
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
export const getErrorStatus = (error: Error): { status: number, message: string} | undefined => {
|
||||
const formattedError = JSON.parse(JSON.stringify(error))
|
||||
export const getErrorStatus = (
|
||||
error: Error
|
||||
): { status: number; message: string } | undefined => {
|
||||
const formattedError = JSON.parse(JSON.stringify(error))
|
||||
|
||||
if ("status" in formattedError && "message" in formattedError) {
|
||||
return { status: formattedError.status, message: formattedError.message }
|
||||
}
|
||||
if ("status" in formattedError && "message" in formattedError) {
|
||||
return { status: formattedError.status, message: formattedError.message }
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ const units: [RelativeTimeFormatUnit, string, number][] = [
|
||||
["day", "d", 86400000],
|
||||
["hour", "h", 3600000],
|
||||
["minute", "m", 60000],
|
||||
];
|
||||
]
|
||||
|
||||
const getRelativeTime = (dates: { from: Date | string; to: Date | string }) => {
|
||||
const elapsed = new Date(dates.to).getTime() - new Date(dates.from).getTime()
|
||||
@@ -15,24 +15,21 @@ const getRelativeTime = (dates: { from: Date | string; to: Date | string }) => {
|
||||
const suffix = elapsed <= 0 ? "ago" : ""
|
||||
const prefix = elapsed > 0 ? "in" : ""
|
||||
const indicator = Math.abs(elapsed) < 1 ? "<" : ""
|
||||
const timeToShow = Math.max(
|
||||
1,
|
||||
Math.abs(Math.round(elapsed / amount))
|
||||
)
|
||||
const timeToShow = Math.max(1, Math.abs(Math.round(elapsed / amount)))
|
||||
|
||||
return {
|
||||
raw: elapsed,
|
||||
rtf: `
|
||||
${indicator}${prefix ? prefix + " " : ""}
|
||||
${(isLessThan1Min ? "< " : "")}
|
||||
${isLessThan1Min ? "< " : ""}
|
||||
${timeToShow}${displayedUnit}
|
||||
${suffix}
|
||||
`
|
||||
};
|
||||
`,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { raw: 0, rtf: "" }
|
||||
};
|
||||
}
|
||||
|
||||
export default getRelativeTime
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import React from "react"
|
||||
import {
|
||||
DeepMap,
|
||||
FieldError,
|
||||
@@ -49,7 +48,7 @@ function getFormErrors(errors: DeepMap<FieldValues, FieldError>) {
|
||||
}, [])
|
||||
|
||||
const list = (
|
||||
<ul className="list-disc list-inside">
|
||||
<ul className="list-inside list-disc">
|
||||
{messages.map((m) => (
|
||||
<li>{m}</li>
|
||||
))}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Medusa from "../services/api";
|
||||
import { FormImage } from "../types/shared";
|
||||
import Medusa from "../services/api"
|
||||
import { FormImage } from "../types/shared"
|
||||
|
||||
const splitImages = (
|
||||
images: FormImage[]
|
||||
@@ -30,4 +30,4 @@ export const prepareImages = async (images: FormImage[]) => {
|
||||
}
|
||||
|
||||
return [...existingImages, ...uploadedImgs]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
|
||||
import { get } from "lodash"
|
||||
import { FieldPath, FieldValues, UseFormReturn } from "react-hook-form"
|
||||
import { Get } from "type-fest"
|
||||
|
||||
export type NestedForm<TValues extends FieldValues> = UseFormReturn<{ __nested__: TValues }> & {
|
||||
export type NestedForm<TValues extends FieldValues> = UseFormReturn<{
|
||||
__nested__: TValues
|
||||
}> & {
|
||||
path(this: void): `__nested__`
|
||||
path<TPath extends FieldPath<TValues>>(
|
||||
this: void,
|
||||
@@ -19,11 +20,11 @@ export type NestedForm<TValues extends FieldValues> = UseFormReturn<{ __nested__
|
||||
/**
|
||||
* Utility function to create a nested form. This is useful when you want to use a reusable form component within a form.
|
||||
* This is especially useful when you want to use a reusable form component within a form multiple times. For example, an form
|
||||
* that contains both a billing and a shipping address.
|
||||
* that contains both a billing and a shipping address.
|
||||
* @example
|
||||
* const MyForm = () => {
|
||||
* const form = useForm<{ email: string, shipping_address: AddressPayload, billing_address: AddressPayload }>()
|
||||
*
|
||||
*
|
||||
* return (
|
||||
* <div>
|
||||
* <Input {...form.register("email")} label="email" />
|
||||
@@ -32,14 +33,14 @@ export type NestedForm<TValues extends FieldValues> = UseFormReturn<{ __nested__
|
||||
* </div>
|
||||
* )
|
||||
* }
|
||||
*
|
||||
*
|
||||
* type AddressFormProps = {
|
||||
* form: NestedForm<AddressPayload>
|
||||
* }
|
||||
*
|
||||
*
|
||||
* const AddressForm = ({ form }: AddressFormProps) => {
|
||||
* const { register, path } = form
|
||||
*
|
||||
*
|
||||
* return (
|
||||
* <div>
|
||||
* <Input {...register(path("city"))} label="City" /> // path("city") resolves as "shipping_address.city" or "billing_address.city" depending on the second argument passed to nestedForm
|
||||
@@ -51,7 +52,10 @@ export type NestedForm<TValues extends FieldValues> = UseFormReturn<{ __nested__
|
||||
export function nestedForm<TValues extends FieldValues>(
|
||||
form: UseFormReturn<TValues> | NestedForm<TValues>
|
||||
): NestedForm<TValues>
|
||||
export function nestedForm<TValues extends FieldValues, TPath extends FieldPath<TValues>>(
|
||||
export function nestedForm<
|
||||
TValues extends FieldValues,
|
||||
TPath extends FieldPath<TValues>
|
||||
>(
|
||||
form: UseFormReturn<TValues> | NestedForm<TValues>,
|
||||
path: TPath
|
||||
): NestedForm<Get<TValues, TPath>>
|
||||
@@ -63,7 +67,7 @@ export function nestedForm(
|
||||
...form,
|
||||
path(field?: string | number) {
|
||||
const fullPath = path && field ? `${path}.${field}` : path ? path : field
|
||||
|
||||
|
||||
if ("path" in form) {
|
||||
return form.path(path as any)
|
||||
}
|
||||
@@ -72,12 +76,12 @@ export function nestedForm(
|
||||
},
|
||||
get(obj: any, field?: string | number) {
|
||||
const fullPath = path && field ? `${path}.${field}` : path ? path : field
|
||||
|
||||
if ("get" in form) {
|
||||
return form.get(path)
|
||||
|
||||
if ("get" in form) {
|
||||
return form.get(path)
|
||||
}
|
||||
|
||||
|
||||
return fullPath ? get(obj, fullPath) : obj
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import { SalesChannel } from "@medusajs/medusa"
|
||||
|
||||
export const defaultChannelsSorter = (defaultSalesChanenlId: string) => (
|
||||
sc1: SalesChannel,
|
||||
sc2: SalesChannel
|
||||
) => {
|
||||
if (sc1.id === defaultSalesChanenlId) {
|
||||
return -1
|
||||
}
|
||||
if (sc2.id === defaultSalesChanenlId) {
|
||||
return 1
|
||||
}
|
||||
export const defaultChannelsSorter =
|
||||
(defaultSalesChanenlId: string) => (sc1: SalesChannel, sc2: SalesChannel) => {
|
||||
if (sc1.id === defaultSalesChanenlId) {
|
||||
return -1
|
||||
}
|
||||
if (sc2.id === defaultSalesChanenlId) {
|
||||
return 1
|
||||
}
|
||||
|
||||
return sc1.name.localeCompare(sc2.name)
|
||||
}
|
||||
return sc1.name.localeCompare(sc2.name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user