-
Notifications
You must be signed in to change notification settings - Fork 0
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 #49 from Prodeko:post-signup-migration
Post-signup-migration
- Loading branch information
Showing
8 changed files
with
217 additions
and
21 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
prisma/migrations/20241105162607_relate_user_to_legacyuser/migration.sql
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,16 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `alreadyMigrated` on the `LegacyUser` table. All the data in the column will be lost. | ||
- A unique constraint covering the columns `[newAccountId]` on the table `LegacyUser` will be added. If there are existing duplicate values, this will fail. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "LegacyUser" DROP COLUMN "alreadyMigrated", | ||
ADD COLUMN "newAccountId" INTEGER; | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "LegacyUser_newAccountId_key" ON "LegacyUser"("newAccountId"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "LegacyUser" ADD CONSTRAINT "LegacyUser_newAccountId_fkey" FOREIGN KEY ("newAccountId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; |
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,67 @@ | ||
import { useActionState, useEffect, useRef, useState } from "react"; | ||
import toast from "react-hot-toast"; | ||
|
||
import { AnimatedPopup, PopupRefActions } from "@/components/ui/AnimatedPopup"; | ||
import { FatButton } from "@/components/ui/Buttons/FatButton"; | ||
import { LineButton } from "@/components/ui/Buttons/LineButton"; | ||
import { DialogTitleWithButton } from "@/components/ui/DialogTitleWithButton"; | ||
import { MigrationCombobox } from "@/components/ui/MigrationCombobox"; | ||
import { migrateAccountAction } from "@/server/actions/account/migration"; | ||
|
||
export const AccountMigrationDialog = () => { | ||
const [step, setStep] = useState(0); | ||
const [result, formAction, isPending] = useActionState(migrateAccountAction, { | ||
success: false, | ||
error: undefined, | ||
}); | ||
|
||
useEffect(() => { | ||
if (result?.error) { | ||
toast.error(result.error); | ||
} else if (result?.success) { | ||
toast.success("Account migrated successfully!"); | ||
closeModal(); | ||
} | ||
}, [result]); | ||
const popupRef = useRef<PopupRefActions>(undefined); | ||
const closeModal = () => { | ||
popupRef?.current?.closeContainer(); | ||
setStep(0); | ||
}; | ||
|
||
const setupButton = ( | ||
<LineButton text="Migrate old account" buttonType="button" /> | ||
); | ||
|
||
return ( | ||
<AnimatedPopup ref={popupRef} TriggerComponent={setupButton}> | ||
<div className="flex flex-col items-center gap-4 px-6 py-6 md:gap-12 md:px-16 md:py-12"> | ||
<DialogTitleWithButton | ||
title="Account migration" | ||
onButtonClick={closeModal} | ||
/> | ||
<p className="text-md text-neutral-700 md:text-xl "> | ||
Have an old Namukilke account you want to migrate? Use the form below | ||
to move your old account's funds to this one. <br /> | ||
</p> | ||
<p className="text-md text-red-400 md:text-xl"> | ||
Note that you can only migrate one account. | ||
</p> | ||
<form | ||
action={formAction} | ||
className="flex flex-col items-center gap-4 md:gap-12" | ||
> | ||
<MigrationCombobox /> | ||
<FatButton | ||
buttonType="button" | ||
type="submit" | ||
text="Migrate account" | ||
intent="primary" | ||
loading={isPending} | ||
fullwidth | ||
/> | ||
</form> | ||
</div> | ||
</AnimatedPopup> | ||
); | ||
}; |
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,21 @@ | ||
import { HiX } from "react-icons/hi"; | ||
|
||
interface Props { | ||
title: string; | ||
onButtonClick: () => void; | ||
} | ||
|
||
export const DialogTitleWithButton = ({ title, onButtonClick }: Props) => { | ||
return ( | ||
<div className="flex w-full items-center justify-between md:-mb-12"> | ||
<p className="text-lg font-bold text-primary-400 md:text-3xl">{title}</p> | ||
{/* biome-ignore lint/a11y/useKeyWithClickEvents: <explanation> */} | ||
<div | ||
className="flex h-10 w-10 items-center justify-center rounded-full border-2 border-primary-400 bg-primary-50 text-2xl text-primary-400 md:h-16 md:w-16 md:border-2 md:text-4xl" | ||
onClick={onButtonClick} | ||
> | ||
<HiX /> | ||
</div> | ||
</div> | ||
); | ||
}; |
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