Skip to content

Commit

Permalink
Merge pull request #95 from DeveloperRyou/develop
Browse files Browse the repository at this point in the history
FIX: 직원초대 기능 수정, 카카오로그인 수정
  • Loading branch information
DeveloperRyou authored Jun 27, 2024
2 parents c366af9 + f61925b commit 106ef37
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
21 changes: 19 additions & 2 deletions src/assist/buttonwrapper/KakaoLoginButtonWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
import { createRandomString } from "@/libs/createRandomId";
import LoginButton from "@modules/components/button/LoginButton";
import FlexBox from "@modules/layout/FlexBox";
import { useRouter } from "next/router";
import { useState } from "react";

function KakaoLoginButtonWrapper() {
const { push } = useRouter();
const [clickedNumber, setClickedNumber] = useState(0);
const redirectUri = `${window.location.origin}/oauth/kakao`;
const kakaoSDKLogin = () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const kakao = (window as any).Kakao;
if (!kakao?.isInitialized()) {
kakao?.init(process.env.NEXT_PUBLIC_KAKAO_JS_KEY);
}
const redirectUri = `${window.location.origin}/oauth/kakao`;
kakao?.Auth?.authorize({
redirectUri,
state: createRandomString(32),
});
};
const kakaoRESTLogin = () => {
push(
`https://kauth.kakao.com/oauth/authorize?redirect_uri=${redirectUri}&client_id=${process.env.NEXT_PUBLIC_KAKAO_REST_KEY}&response_type=code`,
);
};

return (
<FlexBox className="px-4 w-full justify-center">
<div className="w-full max-w-[360px]">
<LoginButton type="kakao" onClick={kakaoSDKLogin} />
<LoginButton
type="kakao"
onClick={() => {
if (clickedNumber === 0) kakaoSDKLogin();
else kakaoRESTLogin();
setClickedNumber(clickedNumber + 1);
}}
/>
</div>
</FlexBox>
);
Expand Down
23 changes: 5 additions & 18 deletions src/pages/manage/confirm.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import React, { useState } from "react";
import { useRouter } from "next/router";
import FlexBox from "@modules/layout/FlexBox";
import TopTitle from "@modules/layout/TopTitle";
import TextButton from "@modules/components/button/TextButton";
import ConfirmEmployee from "@/screen/manage/ConfirmEmployee";
import ShareLink from "@/screen/manage/ShareLink";
import { InviteSchedule, inviteScheduleInit } from "@/data/inviteSchedule";

function setSelectedPostion(arg0: string) {
console.log(arg0);
throw new Error("Function not implemented.");
}

function setInviteSchedule(inviteSchedule: InviteSchedule) {
console.log(inviteSchedule);
throw new Error("Function not implemented.");
}
import TextButton from "@modules/components/button/TextButton";
import FlexBox from "@modules/layout/FlexBox";
import TopTitle from "@modules/layout/TopTitle";
import { useRouter } from "next/router";
import { useState } from "react";

type View = "confirm" | "share";

Expand All @@ -28,8 +17,6 @@ export default function Home() {
};

const handleShiftButton = () => {
setSelectedPostion("");
setInviteSchedule(inviteScheduleInit);
router.push("/manage");
};

Expand Down
2 changes: 1 addition & 1 deletion src/pages/oauth/kakao.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function Kakao() {
const { mutate: postKakaoLoginMutate } = useKakaoLogin();

useEffect(() => {
if (code && state) {
if (code) {
postKakaoLoginMutate({
data: {
code,
Expand Down
20 changes: 11 additions & 9 deletions src/screen/manage/ShareLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ interface InviteDataType {
}

function ShareLink() {
const [inviteId, setInviteId] = useState<string>("");
const [linkCopied, setLinkCopied] = useState(false);
const [inviteSchedule] = useAtom(inviteScheduleAtom);
const [selectedPosition] = useAtom(selectedPositionAtom);
const [storeId] = useAtom(storeIdAtom);

const inviteId = createRandomString(8);
const handleCopyLink = (id: string) => {
const link = `${window.location.origin}/?id=${id}`;
if (!inviteId) setInviteId(createRandomString(8));

const handleCopyLink = () => {
const link = `${window.location.origin}/?id=${inviteId}`;
copy(
link,
() => {
Expand All @@ -45,27 +47,27 @@ function ShareLink() {
);
};

const sendInviteToDB = async (id: string) => {
const sendInviteToDB = async () => {
const inviteData: InviteDataType = {
storeId,
position: selectedPosition,
schedule: inviteSchedule,
createdAt: dayjs().format("YYYY-MM-DD HH:mm:ss"),
};
const data = {
id,
id: inviteId,
inviteData,
};
try {
await axios.post("/api/dynamoDB", data);
handleCopyLink(inviteId);
handleCopyLink();
} catch (error) {
console.error("Failed to create invite:", error);
alert("초대링크 생성에 실패했습니다.");
}
};

useEffect(() => {
sendInviteToDB(inviteId);
sendInviteToDB();
}, []);

return (
Expand All @@ -89,7 +91,7 @@ function ShareLink() {
<div className="B1-medium text-Gray5 mt-4">
링크복사가 안되었나요?
</div>
<button onClick={() => handleCopyLink(inviteId)} type="button">
<button onClick={() => handleCopyLink()} type="button">
<FlexBox direction="row">
<div className="B4-regular text-Gray4 underline">링크 복사</div>
<div className="B4-regular text-Gray4">하기</div>
Expand Down

0 comments on commit 106ef37

Please sign in to comment.