Compare commits
2 Commits
a1b4a016fa
...
70f4f86dc3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70f4f86dc3 | ||
|
|
13a7341494 |
|
|
@ -1,7 +1,6 @@
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Form, Formik, FormikConfig, FormikErrors, FormikProps } from "formik";
|
import { Form, Formik, FormikConfig, FormikErrors, FormikProps } from "formik";
|
||||||
import { Divider } from "@shared/nej-react-components/Parts/Text";
|
import { Button, Divider } from "@mantine/core";
|
||||||
import Button from "@shared/nej-react-components/Parts/Button";
|
|
||||||
|
|
||||||
//formik is defined as
|
//formik is defined as
|
||||||
//export declare function Formik<Values extends FormikValues = FormikValues, ExtraProps = {}>(props: FormikConfig<Values> & ExtraProps): React.JSX.Element;
|
//export declare function Formik<Values extends FormikValues = FormikValues, ExtraProps = {}>(props: FormikConfig<Values> & ExtraProps): React.JSX.Element;
|
||||||
|
|
@ -37,9 +36,9 @@ export function FormikForm<Values extends object>({
|
||||||
<Form>
|
<Form>
|
||||||
{createForm && createForm(values, handleChange, errors, touched)}
|
{createForm && createForm(values, handleChange, errors, touched)}
|
||||||
{children}
|
{children}
|
||||||
<Divider />
|
<Divider my="md" />
|
||||||
<div tw="flex justify-center items-center">
|
<div tw="flex justify-center items-center">
|
||||||
{onDelete && <Button onClick={onDelete} type="error">{t("Delete")}</Button>}
|
{onDelete && <Button onClick={onDelete} color="red">{t("Delete")}</Button>}
|
||||||
{closeModal && <Button onClick={() => closeModal()}>{t("Close")}</Button>}
|
{closeModal && <Button onClick={() => closeModal()}>{t("Close")}</Button>}
|
||||||
<Button type="submit">{submitText}</Button>
|
<Button type="submit">{submitText}</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,19 @@
|
||||||
import { FormikForm } from "@shared/nej-react-utils/Form/FormikForm";
|
import { FormikForm } from "@shared/nej-react-utils/Form/FormikForm";
|
||||||
import { NejAccountingApiClient, CompanyResponse, CancelablePromise } from "@services/accounting-api";
|
import { useApiClient, useProject } from "@utils/NejManager/NejProvider";
|
||||||
import { useApiClient, useCompany } from "@utils/NejManager/NejProvider";
|
|
||||||
import useMethod from "../macros/useMethod.macro";
|
import useMethod from "../macros/useMethod.macro";
|
||||||
import useQuery from "../macros/useQuery.macro";
|
import useQuery from "../macros/useQuery.macro";
|
||||||
|
import { CancelablePromise, PortalApiClient, ProjectResponse } from "@services/portal-api";
|
||||||
|
|
||||||
type FormProps<T> = {
|
type FormProps<T> = {
|
||||||
refresh: () => void;
|
refresh: () => void;
|
||||||
|
afterSubmit?: (values: T) => void;
|
||||||
initialData?: T;
|
initialData?: T;
|
||||||
};
|
};
|
||||||
export type WithFormProps<T, P> = P & FormProps<T>;
|
export type WithFormProps<T, P> = P & FormProps<T>;
|
||||||
export function withForm<T extends object, P extends FormProps<T>>(WrappedForm: React.ComponentType, method: (client: NejAccountingApiClient, company: CompanyResponse, props: P) => (body: T) => CancelablePromise<any>, submitText: string) {
|
export function withForm<T extends object, P extends FormProps<T>>(WrappedForm: React.ComponentType, method: (client: PortalApiClient, project: ProjectResponse, props: P) => (body: T) => CancelablePromise<any>, submitText: string) {
|
||||||
return function GameFormWrapper({ refresh, initialData, ...props }: P) {
|
return function GameFormWrapper({ refresh, afterSubmit, initialData, ...props }: P) {
|
||||||
const client = useApiClient();
|
const client = useApiClient();
|
||||||
const company = useCompany();
|
const company = useProject();
|
||||||
|
|
||||||
const fnc = method(client, company, { ...props, initialData } as P);
|
const fnc = method(client, company, { ...props, initialData } as P);
|
||||||
console.log(fnc);
|
console.log(fnc);
|
||||||
|
|
@ -25,7 +26,7 @@ export function withForm<T extends object, P extends FormProps<T>>(WrappedForm:
|
||||||
return (
|
return (
|
||||||
<FormikForm
|
<FormikForm
|
||||||
data={initialData || {} as T}
|
data={initialData || {} as T}
|
||||||
onSubmit={(values) => submit(values)}
|
onSubmit={(values) => {submit(values); afterSubmit && afterSubmit(values)}}
|
||||||
submitText={submitText}
|
submitText={submitText}
|
||||||
>
|
>
|
||||||
<WrappedForm />
|
<WrappedForm />
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,18 @@
|
||||||
import { MantineReactTable, MRT_RowData, MRT_TableInstance, MRT_TableOptions, useMantineReactTable, Xor } from "mantine-react-table";
|
import { MantineReactTable, MRT_Cell, MRT_Column, MRT_Row, MRT_RowData, MRT_TableInstance, MRT_TableOptions, useMantineReactTable, Xor } from "mantine-react-table";
|
||||||
import { useNejReactTable } from "./useNejReactTable";
|
import { useNejReactTable } from "./useNejReactTable";
|
||||||
|
import { LoadingOverlay } from "@mantine/core";
|
||||||
|
import { ReactNode, RefObject } from "react";
|
||||||
|
|
||||||
|
export type TableInstance<TData extends MRT_RowData> = MRT_TableInstance<TData> & { loading: boolean }
|
||||||
type TableInstanceProp<TData extends MRT_RowData> = {
|
type TableInstanceProp<TData extends MRT_RowData> = {
|
||||||
table: MRT_TableInstance<TData>;
|
table: TableInstance<TData>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type NejReactTableOptions<TData extends MRT_RowData> = Omit<MRT_TableOptions<TData>, "data"> & { data?: TData[] };
|
||||||
|
|
||||||
type Props<TData extends MRT_RowData> = Xor<
|
type Props<TData extends MRT_RowData> = Xor<
|
||||||
TableInstanceProp<TData>,
|
TableInstanceProp<TData>,
|
||||||
MRT_TableOptions<TData>
|
NejReactTableOptions<TData>
|
||||||
>;
|
>;
|
||||||
|
|
||||||
const isTableInstanceProp = <TData extends MRT_RowData>(
|
const isTableInstanceProp = <TData extends MRT_RowData>(
|
||||||
|
|
@ -15,10 +20,21 @@ const isTableInstanceProp = <TData extends MRT_RowData>(
|
||||||
): props is TableInstanceProp<TData> =>
|
): props is TableInstanceProp<TData> =>
|
||||||
(props as TableInstanceProp<TData>).table !== undefined;
|
(props as TableInstanceProp<TData>).table !== undefined;
|
||||||
|
|
||||||
|
export type RenderActionType<TData extends MRT_RowData, TValue = unknown> = (data: {
|
||||||
|
cell: MRT_Cell<TData, TValue>;
|
||||||
|
column: MRT_Column<TData, TValue>;
|
||||||
|
renderedCellValue: ReactNode | number | string;
|
||||||
|
renderedColumnIndex?: number;
|
||||||
|
renderedRowIndex?: number;
|
||||||
|
row: MRT_Row<TData>;
|
||||||
|
rowRef?: RefObject<HTMLTableRowElement>;
|
||||||
|
table: MRT_TableInstance<TData>;
|
||||||
|
}) => React.ReactNode
|
||||||
|
|
||||||
export const NejReactTable = <TData extends MRT_RowData>(
|
export const NejReactTable = <TData extends MRT_RowData>(
|
||||||
props: Props<TData>,
|
props: Props<TData>,
|
||||||
) => {
|
) => {
|
||||||
let table: MRT_TableInstance<TData>;
|
let table: TableInstance<TData>;
|
||||||
|
|
||||||
if (isTableInstanceProp(props)) {
|
if (isTableInstanceProp(props)) {
|
||||||
table = props.table;
|
table = props.table;
|
||||||
|
|
@ -26,5 +42,8 @@ export const NejReactTable = <TData extends MRT_RowData>(
|
||||||
table = useNejReactTable(props);
|
table = useNejReactTable(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
return <MantineReactTable {...props} />;
|
return <div tw="relative">
|
||||||
|
<LoadingOverlay visible={table.loading} />
|
||||||
|
<MantineReactTable table={table} />
|
||||||
|
</div>;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
|
import { useCallback } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
export function useNumberFormat() {
|
export function useNumberFormat() {
|
||||||
const { i18n } = useTranslation();
|
const { i18n } = useTranslation();
|
||||||
|
|
||||||
return (number, digits=2, currency=null) => {
|
return (number: number, digits = 2, currency = null) => {
|
||||||
if (currency) {
|
if (currency) {
|
||||||
if ((Math.round(number * (10 ** digits)) / (10 ** digits)) === 0)
|
if ((Math.round(number * (10 ** digits)) / (10 ** digits)) === 0)
|
||||||
return "---";
|
return "---";
|
||||||
|
|
@ -25,7 +26,7 @@ export function useNumberFormat() {
|
||||||
export function useDateFormat() {
|
export function useDateFormat() {
|
||||||
const { i18n } = useTranslation();
|
const { i18n } = useTranslation();
|
||||||
|
|
||||||
return (date) => {
|
return (date: Date | string) => {
|
||||||
if (typeof date === "undefined") return "---";
|
if (typeof date === "undefined") return "---";
|
||||||
if (typeof date === "string") date = new Date(date);
|
if (typeof date === "string") date = new Date(date);
|
||||||
|
|
||||||
|
|
@ -39,7 +40,7 @@ export function useDateFormat() {
|
||||||
export function useDateTimeFormat() {
|
export function useDateTimeFormat() {
|
||||||
const { i18n } = useTranslation();
|
const { i18n } = useTranslation();
|
||||||
|
|
||||||
return (date) => {
|
return (date: Date | string) => {
|
||||||
if (typeof date === "undefined") return "---";
|
if (typeof date === "undefined") return "---";
|
||||||
if (typeof date === "string") date = new Date(date);
|
if (typeof date === "string") date = new Date(date);
|
||||||
|
|
||||||
|
|
@ -54,3 +55,25 @@ export function useDateTimeFormat() {
|
||||||
}).format(date);
|
}).format(date);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useLanguageFormat(){
|
||||||
|
const { i18n } = useTranslation();
|
||||||
|
|
||||||
|
return useCallback((language: string) => {
|
||||||
|
return new Intl.DisplayNames(i18n.language, {
|
||||||
|
type: "language",
|
||||||
|
style: "short",
|
||||||
|
}).of(language);
|
||||||
|
}, [i18n.language]);
|
||||||
|
}
|
||||||
|
export function useCountryFormat(){
|
||||||
|
const { i18n } = useTranslation();
|
||||||
|
|
||||||
|
return (region: string) => {
|
||||||
|
return new Intl.DisplayNames(i18n.language, {
|
||||||
|
type: "region",
|
||||||
|
style: "short",
|
||||||
|
|
||||||
|
}).of(region);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ export default function useModal<T>(
|
||||||
const openModal = useCallback((params: T) => {
|
const openModal = useCallback((params: T) => {
|
||||||
modals.open({
|
modals.open({
|
||||||
title,
|
title,
|
||||||
children: <Component {...params} />,
|
children: <Component afterSubmit={() => modals.closeAll()} {...params} />,
|
||||||
});
|
});
|
||||||
}, [Component, title]);
|
}, [Component, title]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user