Files
swiss-datashare/frontend/src/components/upload/modals/showCompletedUploadModal.tsx

65 lines
1.8 KiB
TypeScript
Raw Normal View History

import { Button, Stack, Text } from "@mantine/core";
2022-04-25 15:15:17 +02:00
import { useModals } from "@mantine/modals";
import { ModalsContextProps } from "@mantine/modals/lib/context";
import moment from "moment";
2022-04-25 15:15:17 +02:00
import { useRouter } from "next/router";
import { FormattedMessage } from "react-intl";
import useTranslate, {
translateOutsideContext,
} from "../../../hooks/useTranslate.hook";
2022-10-18 14:27:14 +02:00
import { Share } from "../../../types/share.type";
import CopyTextField from "../CopyTextField";
2023-01-11 13:06:38 +01:00
const showCompletedUploadModal = (
modals: ModalsContextProps,
share: Share,
2023-08-17 14:47:58 +02:00
appUrl: string,
2023-01-11 13:06:38 +01:00
) => {
const t = translateOutsideContext();
2022-04-25 15:15:17 +02:00
return modals.openModal({
closeOnClickOutside: false,
withCloseButton: false,
closeOnEscape: false,
title: t("upload.modal.completed.share-ready"),
2023-01-11 13:06:38 +01:00
children: <Body share={share} appUrl={appUrl} />,
2022-04-25 15:15:17 +02:00
});
};
2023-01-11 13:06:38 +01:00
const Body = ({ share, appUrl }: { share: Share; appUrl: string }) => {
2022-04-25 15:15:17 +02:00
const modals = useModals();
const router = useRouter();
const t = useTranslate();
2023-01-11 13:06:38 +01:00
2023-07-22 16:09:10 +02:00
const link = `${appUrl}/s/${share.id}`;
2022-04-25 15:15:17 +02:00
return (
<Stack align="stretch">
<CopyTextField link={link} />
2022-04-25 15:15:17 +02:00
<Text
size="xs"
sx={(theme) => ({
color: theme.colors.gray[6],
})}
>
{/* If our share.expiration is timestamp 0, show a different message */}
{moment(share.expiration).unix() === 0
? t("upload.modal.completed.never-expires")
: t("upload.modal.completed.expires-on", {
expiration: moment(share.expiration).format("LLL"),
})}
2022-04-25 15:15:17 +02:00
</Text>
<Button
onClick={() => {
modals.closeAll();
router.push("/upload");
}}
>
<FormattedMessage id="common.button.done" />
2022-04-25 15:15:17 +02:00
</Button>
2022-10-10 22:14:23 +02:00
</Stack>
2022-04-25 15:15:17 +02:00
);
};
export default showCompletedUploadModal;