2022-01-14 15:50:02 +01:00
|
|
|
import { useStyles } from './FormTemplate.styles';
|
|
|
|
import MenuBookIcon from '@material-ui/icons/MenuBook';
|
|
|
|
import Codebox from '../Codebox/Codebox';
|
2022-03-14 13:14:26 +01:00
|
|
|
import { Collapse, IconButton, useMediaQuery } from '@material-ui/core';
|
|
|
|
import { FileCopy, Info } from '@material-ui/icons';
|
2022-01-14 15:50:02 +01:00
|
|
|
import ConditionallyRender from '../ConditionallyRender';
|
|
|
|
import Loader from '../Loader/Loader';
|
|
|
|
import copy from 'copy-to-clipboard';
|
2022-03-28 10:49:59 +02:00
|
|
|
import useToast from 'hooks/useToast';
|
2022-03-14 13:14:26 +01:00
|
|
|
import React, { useState } from 'react';
|
2022-03-09 14:59:24 +01:00
|
|
|
import classNames from 'classnames';
|
2022-03-25 12:34:20 +01:00
|
|
|
import { ReactComponent as MobileGuidanceBG } from 'assets/img/mobileGuidanceBg.svg';
|
2022-03-14 13:14:26 +01:00
|
|
|
import { useCommonStyles } from 'common.styles';
|
2022-01-14 15:50:02 +01:00
|
|
|
|
|
|
|
interface ICreateProps {
|
|
|
|
title: string;
|
|
|
|
description: string;
|
|
|
|
documentationLink: string;
|
|
|
|
loading?: boolean;
|
2022-03-09 14:59:24 +01:00
|
|
|
modal?: boolean;
|
2022-01-14 15:50:02 +01:00
|
|
|
formatApiCode: () => string;
|
|
|
|
}
|
|
|
|
|
2022-03-14 13:14:26 +01:00
|
|
|
// Components in this file:
|
|
|
|
// FormTemplate
|
|
|
|
// MobileGuidance
|
|
|
|
// Guidance
|
|
|
|
|
2022-01-14 15:50:02 +01:00
|
|
|
const FormTemplate: React.FC<ICreateProps> = ({
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
children,
|
|
|
|
documentationLink,
|
|
|
|
loading,
|
2022-03-09 14:59:24 +01:00
|
|
|
modal,
|
2022-01-14 15:50:02 +01:00
|
|
|
formatApiCode,
|
|
|
|
}) => {
|
|
|
|
const { setToastData } = useToast();
|
|
|
|
const styles = useStyles();
|
2022-03-14 13:14:26 +01:00
|
|
|
const commonStyles = useCommonStyles();
|
2022-03-21 15:45:07 +01:00
|
|
|
const smallScreen = useMediaQuery(`(max-width:${899}px)`);
|
2022-01-14 15:50:02 +01:00
|
|
|
|
|
|
|
const copyCommand = () => {
|
|
|
|
if (copy(formatApiCode())) {
|
|
|
|
setToastData({
|
|
|
|
title: 'Successfully copied the command',
|
|
|
|
text: 'The command should now be automatically copied to your clipboard',
|
|
|
|
autoHideDuration: 6000,
|
|
|
|
type: 'success',
|
|
|
|
show: true,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
setToastData({
|
|
|
|
title: 'Could not copy the command',
|
|
|
|
text: 'Sorry, but we could not copy the command.',
|
|
|
|
autoHideDuration: 6000,
|
|
|
|
type: 'error',
|
|
|
|
show: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2022-03-09 14:59:24 +01:00
|
|
|
<section
|
|
|
|
className={classNames(styles.container, modal && styles.modal)}
|
|
|
|
>
|
2022-03-14 13:14:26 +01:00
|
|
|
<ConditionallyRender
|
|
|
|
condition={smallScreen}
|
|
|
|
show={
|
|
|
|
<div className={commonStyles.relative}>
|
|
|
|
<MobileGuidance
|
|
|
|
description={description}
|
|
|
|
documentationLink={documentationLink}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
2022-01-14 15:50:02 +01:00
|
|
|
<div className={styles.formContent}>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={loading || false}
|
|
|
|
show={<Loader />}
|
2022-03-14 13:14:26 +01:00
|
|
|
elseShow={
|
|
|
|
<>
|
|
|
|
<h2 className={styles.title}>{title}</h2>
|
|
|
|
{children}
|
|
|
|
</>
|
|
|
|
}
|
2022-01-14 15:50:02 +01:00
|
|
|
/>{' '}
|
|
|
|
</div>
|
2022-03-14 13:14:26 +01:00
|
|
|
<ConditionallyRender
|
|
|
|
condition={!smallScreen}
|
|
|
|
show={
|
|
|
|
<Guidance
|
|
|
|
description={description}
|
|
|
|
documentationLink={documentationLink}
|
|
|
|
>
|
|
|
|
<h3 className={styles.subtitle}>
|
|
|
|
API Command{' '}
|
|
|
|
<IconButton onClick={copyCommand}>
|
|
|
|
<FileCopy className={styles.icon} />
|
|
|
|
</IconButton>
|
|
|
|
</h3>
|
|
|
|
<Codebox text={formatApiCode()} />
|
|
|
|
</Guidance>
|
|
|
|
}
|
|
|
|
/>
|
2022-01-14 15:50:02 +01:00
|
|
|
</section>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-03-14 13:14:26 +01:00
|
|
|
interface IMobileGuidance {
|
|
|
|
description: string;
|
|
|
|
documentationLink: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MobileGuidance = ({
|
|
|
|
description,
|
|
|
|
documentationLink,
|
|
|
|
}: IMobileGuidance) => {
|
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
const styles = useStyles();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className={styles.mobileGuidanceBgContainer}>
|
|
|
|
<MobileGuidanceBG className={styles.mobileGuidanceBackground} />
|
|
|
|
</div>
|
|
|
|
<IconButton
|
|
|
|
className={styles.mobileGuidanceButton}
|
|
|
|
onClick={() => setOpen(prev => !prev)}
|
|
|
|
>
|
|
|
|
<Info className={styles.infoIcon} />
|
|
|
|
</IconButton>
|
|
|
|
<Collapse in={open} timeout={500}>
|
|
|
|
<Guidance
|
|
|
|
description={description}
|
|
|
|
documentationLink={documentationLink}
|
|
|
|
/>
|
|
|
|
</Collapse>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
interface IGuidanceProps {
|
|
|
|
description: string;
|
|
|
|
documentationLink: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Guidance: React.FC<IGuidanceProps> = ({
|
|
|
|
description,
|
|
|
|
children,
|
|
|
|
documentationLink,
|
|
|
|
}) => {
|
|
|
|
const styles = useStyles();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<aside className={styles.sidebar}>
|
|
|
|
<p className={styles.description}>{description}</p>
|
|
|
|
|
|
|
|
<div className={styles.linkContainer}>
|
|
|
|
<MenuBookIcon className={styles.linkIcon} />
|
|
|
|
<a
|
|
|
|
className={styles.documentationLink}
|
|
|
|
href={documentationLink}
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
Learn more
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{children}
|
|
|
|
</aside>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-01-14 15:50:02 +01:00
|
|
|
export default FormTemplate;
|