mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-09 04:02:40 -05:00
refresh post logic
This commit is contained in:
parent
ab910e46c9
commit
30de62bbda
|
|
@ -89,8 +89,6 @@ const FAModal: React.FC<Props> = ({ onClose, post }) => {
|
|||
onClose();
|
||||
};
|
||||
|
||||
console.log("ep", errors.playstyles);
|
||||
|
||||
return (
|
||||
<Modal isOpen onClose={onClose} size="xl" closeOnOverlayClick={false}>
|
||||
<ModalOverlay>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import {
|
||||
Alert,
|
||||
AlertDescription,
|
||||
AlertIcon,
|
||||
AlertTitle,
|
||||
Box,
|
||||
Button,
|
||||
Center,
|
||||
|
|
@ -59,17 +61,33 @@ const FreeAgentsPage = () => {
|
|||
const [postIdToScrollTo, setPostIdToScrollTo] = useState<undefined | number>(
|
||||
undefined
|
||||
);
|
||||
const [sending, setSending] = useState(false);
|
||||
const postRef = useRef<HTMLDivElement>(null);
|
||||
const [modalIsOpen, setModalIsOpen] = useState(false);
|
||||
|
||||
console.log("getIdToScrollTo", getIdToScrollTo());
|
||||
|
||||
useEffect(() => {
|
||||
if (!postRef.current) return;
|
||||
|
||||
postRef.current.scrollIntoView();
|
||||
}, [postRef.current]);
|
||||
|
||||
const dateThreeWeeksAgo = new Date();
|
||||
dateThreeWeeksAgo.setDate(dateThreeWeeksAgo.getDate() - 7 * 3);
|
||||
|
||||
const onPostRefresh = async () => {
|
||||
setSending(true);
|
||||
|
||||
const success = await sendData("PUT", "/api/freeagents", {
|
||||
canVC: usersPost!.canVC,
|
||||
playstyles: usersPost!.playstyles,
|
||||
content: usersPost!.content,
|
||||
});
|
||||
setSending(false);
|
||||
if (!success) return;
|
||||
|
||||
mutate("/api/freeagents");
|
||||
};
|
||||
|
||||
return (
|
||||
<MyContainer>
|
||||
{modalIsOpen && (
|
||||
|
|
@ -83,6 +101,42 @@ const FreeAgentsPage = () => {
|
|||
<Trans>New free agent post</Trans>
|
||||
)}
|
||||
</Button>
|
||||
{usersPost &&
|
||||
usersPost.updatedAt.getTime() < dateThreeWeeksAgo.getTime() && (
|
||||
<Alert
|
||||
status="warning"
|
||||
variant="subtle"
|
||||
flexDirection="column"
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
textAlign="center"
|
||||
mx="auto"
|
||||
mt={6}
|
||||
>
|
||||
<AlertIcon boxSize="40px" mr={0} />
|
||||
<AlertTitle mt={4} mb={1} fontSize="lg">
|
||||
<Trans>Your free agent post is about to expire</Trans>
|
||||
</AlertTitle>
|
||||
<AlertDescription maxWidth="sm">
|
||||
<Trans>
|
||||
Free agent posts that haven't been updated in over a month will
|
||||
be hidden. Please press the button below if you are still a free
|
||||
agent.
|
||||
</Trans>
|
||||
|
||||
<Box>
|
||||
<Button
|
||||
mt={4}
|
||||
variant="outline"
|
||||
onClick={onPostRefresh}
|
||||
isLoading={sending}
|
||||
>
|
||||
<Trans>I'm still a free agent</Trans>
|
||||
</Button>
|
||||
</Box>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
{!isLoading && (
|
||||
<Center mt={6}>
|
||||
<RadioGroup
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user