-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from sqrl-planner/feature/facelift
- Loading branch information
Showing
9 changed files
with
309 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from "react" | ||
|
||
import { Box, Button, useDisclosure } from "@chakra-ui/react" | ||
import { useTranslation } from "next-i18next" | ||
import TimetableCreationModal from "./TimetableCreationModal" | ||
|
||
type Props = { | ||
// newLoading: boolean | ||
// setNewLoading: React.Dispatch<React.SetStateAction<boolean>> | ||
timetables: { [id: string]: { key: string; name: string } } | ||
} | ||
|
||
const TimetableCreationButton = ({ | ||
// newLoading, | ||
// setNewLoading, | ||
timetables, | ||
}: Props) => { | ||
const { isOpen, onOpen, onClose } = useDisclosure() | ||
|
||
const { t } = useTranslation("index") | ||
|
||
return ( | ||
<> | ||
<TimetableCreationModal | ||
{...{ | ||
isOpen, | ||
onClose, | ||
timetables, | ||
}} | ||
/> | ||
<Button | ||
border="2px dashed" | ||
rounded="xl" | ||
color="blue.700" | ||
borderColor="blue.500" | ||
display="flex" | ||
justifyContent="center" | ||
alignItems="center" | ||
padding={12} | ||
// disabled={newLoading} | ||
onClick={onOpen} | ||
minH="2xs" | ||
> | ||
<Box | ||
display="flex" | ||
flexDirection="column" | ||
position="relative" | ||
bottom="1" | ||
> | ||
<Box fontSize="7xl">+</Box> | ||
<Box>{t("create-timetable")}</Box> | ||
</Box> | ||
</Button> | ||
</> | ||
) | ||
} | ||
|
||
export default TimetableCreationButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import React, { useState } from "react" | ||
import { | ||
Text, | ||
Flex, | ||
Modal, | ||
ModalOverlay, | ||
ModalContent, | ||
ModalHeader, | ||
ModalFooter, | ||
ModalBody, | ||
ModalCloseButton, | ||
Button, | ||
VStack, | ||
FormControl, | ||
FormHelperText, | ||
Select, | ||
Input, | ||
} from "@chakra-ui/react" | ||
import { useTranslation } from "next-i18next" | ||
import { useMutation } from "@apollo/client" | ||
import { useRouter } from "next/router" | ||
import { CREATE_TIMETABLE } from "../operations/mutations/createTimetable" | ||
|
||
type Props = { | ||
isOpen: boolean | ||
onClose: () => void | ||
timetables: { [id: string]: { key: string; name: string } } | ||
} | ||
|
||
const TimetableCreationModal = ({ isOpen, onClose, timetables }: Props) => { | ||
const { t } = useTranslation("index") | ||
const [newLoading, setNewLoading] = useState(false) | ||
const [name, setName] = useState("") | ||
|
||
const [createTimetable] = useMutation(CREATE_TIMETABLE) | ||
const router = useRouter() | ||
|
||
const createNewTimetable = () => { | ||
setNewLoading(true) | ||
|
||
createTimetable({ | ||
onCompleted: (data) => { | ||
const { | ||
key, | ||
timetable: { id, name }, | ||
} = data.createTimetable | ||
localStorage.setItem( | ||
"timetables", | ||
JSON.stringify({ | ||
...timetables, | ||
[id]: { key, name }, | ||
}) | ||
) | ||
|
||
router.push(`/timetable/${id}`) | ||
}, | ||
variables: { | ||
name: name || undefined, | ||
}, | ||
}) | ||
} | ||
|
||
return ( | ||
<Modal | ||
closeOnEsc={!newLoading} | ||
closeOnOverlayClick={!newLoading} | ||
size="xl" | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<form | ||
onSubmit={(e) => { | ||
e.preventDefault() | ||
createNewTimetable() | ||
}} | ||
> | ||
<ModalHeader>Create a new timetable</ModalHeader> | ||
{!newLoading && <ModalCloseButton />} | ||
<ModalBody> | ||
<VStack width="100%" fontWeight={500} spacing={8}> | ||
<FormControl> | ||
<Flex | ||
width="100%" | ||
alignItems="center" | ||
justifyContent="space-between" | ||
> | ||
<Text as="span" display="flex" alignItems="center"> | ||
{t("select-term")} | ||
</Text> | ||
<Select shadow="sm" fontWeight={500} width="auto"> | ||
<option value="create"> | ||
2022 {t("fall")}–2023 {t("winter")} | ||
</option> | ||
</Select> | ||
</Flex> | ||
<FormHelperText fontWeight={400}> | ||
{t("soon-support-summer-2023")} | ||
</FormHelperText> | ||
</FormControl> | ||
|
||
<FormControl> | ||
<Flex | ||
width="100%" | ||
alignItems="center" | ||
justifyContent="space-between" | ||
> | ||
<Text as="span" display="flex" alignItems="center"> | ||
{t("name")} | ||
</Text> | ||
<Input | ||
value={name} | ||
onChange={(e) => setName(e.target.value)} | ||
autoFocus | ||
width="auto" | ||
/> | ||
</Flex> | ||
<FormHelperText fontWeight={400}> | ||
{t("auto-generated-name")} | ||
</FormHelperText> | ||
</FormControl> | ||
</VStack> | ||
</ModalBody> | ||
|
||
<ModalFooter> | ||
<Button mr={3} variant="ghost" onClick={onClose}> | ||
Cancel | ||
</Button> | ||
<Button type="submit" isLoading={newLoading} colorScheme="blue" bg="blue.700"> | ||
Create timetable | ||
</Button> | ||
</ModalFooter> | ||
</form> | ||
</ModalContent> | ||
</Modal> | ||
) | ||
} | ||
|
||
export default TimetableCreationModal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
bb1b6ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
sqrl-client – ./
sqrl-client-eamonma-s-team.vercel.app
sqrl-client-git-develop-eamonma-s-team.vercel.app
sqrl-client.vercel.app
bb1b6ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
sqrl-client-beta – ./
sqrl-client-beta-git-develop-eamonma-s-team.vercel.app
sqrl-client-beta.vercel.app
sqrl-client-beta-eamonma-s-team.vercel.app