-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move create vesting amount type logic from context to form
- Loading branch information
1 parent
1e3c442
commit 6c090d7
Showing
9 changed files
with
60 additions
and
121 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
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 |
---|---|---|
@@ -1,67 +1,68 @@ | ||
import { Input, Label } from "@bleu/ui"; | ||
import React, { useEffect } from "react"; | ||
import { useFormContext } from "react-hook-form"; | ||
import { useTokenAmountTypeContext } from "#/context/TokenAmountType"; | ||
import { ReactNode, useEffect } from "react"; | ||
import { useFormContext, useWatch } from "react-hook-form"; | ||
|
||
export const FormCheckbox = ({ | ||
export const Checkbox = ({ | ||
name, | ||
state, | ||
setState, | ||
label, | ||
isSelectedMessage, | ||
unselectTrigger, | ||
}: { | ||
name: string; | ||
state: boolean; | ||
setState: (state: boolean) => void; | ||
label?: string; | ||
isSelectedMessage?: string | ReactNode; | ||
unselectTrigger?: boolean; | ||
}) => { | ||
const { setValue } = useFormContext(); | ||
const { register, watch, setValue } = useFormContext(); | ||
const isSelected = watch(name); | ||
|
||
useEffect(() => { | ||
setValue("amount", ""); | ||
setValue(name, state); | ||
}, [name, state, setValue]); | ||
if (unselectTrigger === true) setValue(name, false); | ||
}, [unselectTrigger]); | ||
|
||
return ( | ||
<div className="flex items-center space-x-2"> | ||
<Input | ||
type="checkbox" | ||
id={name} | ||
name={name} | ||
checked={state} | ||
onChange={() => setState(!state)} | ||
className="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600" | ||
/> | ||
<Label | ||
htmlFor={name} | ||
className="text-sm font-medium text-gray-900 dark:text-gray-300" | ||
> | ||
{label} | ||
</Label> | ||
<div className="flex flex-col items-start justify-start"> | ||
<div className="flex items-center space-x-2"> | ||
<Input | ||
type="checkbox" | ||
id={name} | ||
{...register(name)} | ||
className="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600" | ||
/> | ||
<Label | ||
htmlFor={name} | ||
className="text-sm font-medium text-gray-900 dark:text-gray-300" | ||
> | ||
{label} | ||
</Label> | ||
</div> | ||
{isSelected && isSelectedMessage} | ||
</div> | ||
); | ||
}; | ||
|
||
export const VestAllFromSwapCheckbox = () => { | ||
const { vestAllFromSwap, setVestAllFromSwap } = useTokenAmountTypeContext(); | ||
const { control } = useFormContext(); | ||
const { vestAllFromAccount } = useWatch({ control }); | ||
|
||
return ( | ||
<FormCheckbox | ||
<Checkbox | ||
name="vestAllFromSwap" | ||
state={vestAllFromSwap} | ||
setState={setVestAllFromSwap} | ||
label="Use all tokens from swap" | ||
unselectTrigger={vestAllFromAccount} | ||
/> | ||
); | ||
}; | ||
|
||
export const VestAllFromAccountCheckbox = () => { | ||
const { vestAllFromAccount, setVestAllFromAccount } = | ||
useTokenAmountTypeContext(); | ||
const { control } = useFormContext(); | ||
const { vestAllFromSwap } = useWatch({ control }); | ||
|
||
return ( | ||
<FormCheckbox | ||
<Checkbox | ||
name="vestAllFromAccount" | ||
state={vestAllFromAccount} | ||
setState={setVestAllFromAccount} | ||
label="Use all your tokens after swap" | ||
unselectTrigger={vestAllFromSwap} | ||
/> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
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
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