Skip to content

Commit

Permalink
FIX: 직원초대 링크 복사기능 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperRyou committed Jun 10, 2024
1 parent 615fee0 commit 45d9347
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
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
20 changes: 11 additions & 9 deletions src/screen/manage/ShareLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,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 @@ -40,27 +42,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 @@ -84,7 +86,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 45d9347

Please sign in to comment.