-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
14.1 Login-sivun lisääminen Tanstackiin | Antti/add-tanstack-library-login-page #58
Changes from all commits
8eb5a44
5565314
6d45f0e
9475ceb
b4f276c
8fa0406
26703ec
7c61f4a
251f168
d997664
79bfec7
319b087
72977d7
b934a7e
cf85967
df21970
44387b3
41f536e
ed3b883
d19f801
846bd68
6166fbc
41e15fc
7eb7bba
13adf91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,8 +151,8 @@ export default function Home({ | |
|
||
function GiftList() { | ||
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); | ||
const [deleteModalGiftData, setDeleteModalGiftData] = useState<Gift>(); | ||
const [isEditModalOpen, setIsEditModalOpen] = useState(false); | ||
const [deleteModalGiftData, setDeleteModalGiftData] = useState<Gift>(); | ||
const [editModalGiftData, setEditModalGiftData] = useState<Gift>(); | ||
|
||
const { error, isFetching, data: giftData } = useGetGifts(); | ||
|
@@ -203,14 +203,14 @@ function GiftList() { | |
</div> | ||
</div> | ||
))} | ||
{isEditModalOpen && editModalGiftData && ( | ||
{editModalGiftData && isEditModalOpen && ( | ||
<EditModal | ||
gift={editModalGiftData} | ||
setIsModalOpen={setIsEditModalOpen} | ||
/> | ||
)} | ||
|
||
{isDeleteModalOpen && deleteModalGiftData && ( | ||
{deleteModalGiftData && isDeleteModalOpen && ( | ||
Comment on lines
-206
to
+213
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nämä kaksi muutosta liittyy ideaan, jossa poistetaan There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jep tarkistus voidaan hyvin tehdä noin, mikä onkin järkevää ja yksinkertaistaa asioita. Muuttujien järjestyksen muuttaminen ei taida sitä kuitenkaan vielä tehdä? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Joo, ei toimi vielä. Voisin tehdä muokkauksen siihen branchiin, missä lisään Tanstackin Vai onko tämä tarkistus parempi lisätä vasta Tanstackin jälkeen? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Voit tehdä siinä samassa branchissä missä lisäät Tanstackin modaaliin. |
||
<DeleteModal | ||
gift={deleteModalGiftData} | ||
setIsModalOpen={setIsDeleteModalOpen} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,15 @@ import { Logo } from '~/components/Logo'; | |
import { TitleText } from '~/components/TitleText'; | ||
import SvgEyeOpen from '~/icons/eye_open'; | ||
import SvgEyeSlash from '~/icons/eye_slash'; | ||
import { UserLoginDetails } from '~/shared/types'; | ||
import { QueryKeys, UserLoginDetails } from '~/shared/types'; | ||
import { handleError } from '~/utils/handleError'; | ||
import { emailSchema } from '~/shared/zodSchemas'; | ||
import { Label } from '~/components/Label'; | ||
import { GetServerSidePropsContext } from 'next'; | ||
import { handleErrorToast } from '~/utils/handleToasts'; | ||
import { ErrorParagraph } from '~/components/ErrorParagraph'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { useShowErrorToast } from '~/hooks/useShowErrorToast'; | ||
|
||
export async function getServerSideProps(context: GetServerSidePropsContext) { | ||
const cookieData = await validateRequest(context.req, context.res); | ||
|
@@ -46,6 +48,15 @@ export default function Login() { | |
|
||
const router = useRouter(); | ||
|
||
const { mutateAsync, isPending, error } = useMutation({ | ||
mutationKey: QueryKeys.LOGIN, | ||
mutationFn: async (loginCredentials: UserLoginDetails) => | ||
await axios.post('/api/auth/login', loginCredentials), | ||
onSuccess: () => router.push('/'), | ||
}); | ||
|
||
useShowErrorToast(error); | ||
Comment on lines
+51
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
async function handleSubmit(e: FormEvent<HTMLFormElement>) { | ||
e.preventDefault(); | ||
try { | ||
|
@@ -78,14 +89,11 @@ export default function Login() { | |
if (errorFound) { | ||
return; | ||
} | ||
|
||
const loginCredentials: UserLoginDetails = { | ||
email: emailValidation.data || '', | ||
password: password, | ||
rememberMe: rememberMe, | ||
}; | ||
await axios.post('/api/auth/login', loginCredentials); | ||
await router.push('/'); | ||
await mutateAsync({ | ||
email: emailValidation.data ?? '', | ||
password, | ||
rememberMe, | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
handleErrorToast(handleError(e)); | ||
|
@@ -149,7 +157,11 @@ export default function Login() { | |
Muista minut | ||
</Label> | ||
</div> | ||
<Button type="submit">Kirjaudu sisään</Button> | ||
|
||
<Button type="submit" disabled={isPending}> | ||
Kirjaudu sisään{' '} | ||
{isPending && <span className="loading-dots absolute" />} | ||
</Button> | ||
</form> | ||
<p className={`mt-4 text-center text-xs text-gray-500`}> | ||
Ei vielä tunnuksia?{' '} | ||
|
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.
Ovatko nuo värit yhtään sinnepäinkään mitä niiden kuuluisi olla? 😅
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.
Oikein hyvät! 👍