accounts-frontend/packages/app/components/auth/factory.tsx

40 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

import React, { ComponentProps, ComponentType } from 'react';
2020-07-24 21:49:11 +05:30
import { MessageDescriptor } from 'react-intl';
import { Button } from 'app/components/ui/form';
import RejectionLink from 'app/components/auth/RejectionLink';
import AuthTitle from 'app/components/auth/AuthTitle';
2020-07-24 21:49:11 +05:30
import BaseAuthBody from './BaseAuthBody';
2019-12-07 16:58:52 +05:30
export type Factory = () => {
2020-05-24 04:38:24 +05:30
Title: ComponentType;
Body: typeof BaseAuthBody;
Footer: ComponentType;
Links: ComponentType;
};
type RejectionLinkProps = ComponentProps<typeof RejectionLink>;
interface FactoryParams {
2020-05-24 04:38:24 +05:30
title: MessageDescriptor;
body: typeof BaseAuthBody;
2020-07-24 21:49:11 +05:30
footer: Omit<ComponentProps<typeof Button>, 'type'>;
2020-05-24 04:38:24 +05:30
links?: RejectionLinkProps | Array<RejectionLinkProps>;
}
2020-05-24 04:38:24 +05:30
export default function ({ title, body, footer, links }: FactoryParams): Factory {
return () => ({
Title: () => <AuthTitle title={title} />,
Body: body,
Footer: () => <Button type="submit" {...footer} />,
Links: () =>
links ? (
<span>
{([] as Array<RejectionLinkProps>)
.concat(links)
.map((link, index) => [index ? ' | ' : '', <RejectionLink {...link} key={index} />])}
</span>
) : null,
});
2019-12-07 16:58:52 +05:30
}