Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
skorphil committed Feb 26, 2024
1 parent d025b0a commit 22a67fe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 123 deletions.
25 changes: 2 additions & 23 deletions components/InstitutionContainer/InstitutionContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,7 @@ const AssetsList = ({ isInstitutionOpen, institutionName }) => {
} = useFieldArray({
name: arrayName,
});
const {
resetField,
// getValues, // for testing
// setValue, // for testing
// handlers: { handleInstitutionDelete },
formState: { defaultValues },
} = useFormContext();
const { resetField } = useFormContext();

return (
<VStack
Expand All @@ -136,7 +130,6 @@ const AssetsList = ({ isInstitutionOpen, institutionName }) => {
spacing={isInstitutionOpen ? 6 : 2}
align="start"
>
{/* {getValues(`${institutionName}.isDeleted`) && <p>deleted institution</p>} */}
{assets.map((asset, index) => (
<AssetContainer
key={asset.id}
Expand All @@ -145,20 +138,6 @@ const AssetsList = ({ isInstitutionOpen, institutionName }) => {
isCompact={!isInstitutionOpen}
/>
))}
{/* TEST HERE */}
{/* <Button onClick={() => console.log("assets:", assets)}>Log assets</Button>
{/* <Button onClick={() => console.log("dirtyFields:", dirtyFields)}>
Log dirty
</Button>
<Button onClick={() => setValue(`${institutionName}.isDeleted`, true)}>
set isDeleted Value
</Button>
<Button onClick={() => console.log(getValues(`${institutionName}`))}>
get institution Values
</Button>
<Button onClick={() => console.log(defaultValues.institutions[0])}>
get DefaultValues of institution
</Button> */}

{isInstitutionOpen && (
<>
Expand All @@ -178,7 +157,7 @@ const AssetsList = ({ isInstitutionOpen, institutionName }) => {
<ButtonGroup alignSelf="end">
<Button
variant="outline"
// onClick={() => handleInstitutionDelete(institutionIndex)}
onClick={() => handleInstitutionDelete(institutionIndex)}
>
Delete
</Button>
Expand Down
103 changes: 3 additions & 100 deletions components/InstitutionTab/InstitutionTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,125 +2,28 @@

import { IconButton, Tab, forwardRef, Box } from "@chakra-ui/react";
import { CgUndo } from "react-icons/cg";
import { useFormContext, useWatch } from "react-hook-form";
import { useFormContext } from "react-hook-form";
import classes from "./InstitutionTab.module.css";
// const defaultValues = {
// institutions: [
// {
// name: "City Bank",
// country: "it",
// isDeleted: false,
// assets: [
// {
// amount: 10000,
// currency: "usd",
// isEarning: false,
// description: "My Visa debit card",
// },
// {
// amount: 300000,
// currency: "eur",
// isEarning: true,
// description: "My Deposit",
// },
// {
// amount: 1000,
// currency: "cny",
// isEarning: true,
// description: "",
// },
// {
// amount: 5000,
// currency: "chf",
// isEarning: false,
// description: "",
// },
// ],
// },
// {
// name: "Wells & Fargo",
// country: "",
// isDeleted: false,
// assets: [
// {
// amount: 6443,
// currency: "brl",
// isEarning: false,
// description: "Debit card",
// },
// {
// amount: 8765,
// currency: "eur",
// isEarning: true,
// description: "My Deposit",
// },
// {
// amount: 1234,
// currency: "cny",
// isEarning: true,
// description: "",
// },
// ],
// },
// {
// name: "Bank Of America",
// country: "",
// isDeleted: false,
// assets: [
// {
// amount: 1700,
// currency: "usd",
// isEarning: false,
// description: "My Visa debit card",
// },
// {
// amount: 376000,
// currency: "usd",
// isEarning: true,
// description: "My Deposit",
// },
// ],
// },
// {
// name: "Raiffeisen Bank",
// country: "",
// isDeleted: false,
// assets: [
// {
// amount: 888,
// currency: "usd",
// isEarning: false,
// description: "My Visa debit card",
// },
// ],
// },
// ],
// };

export const InstitutionTab = forwardRef(
({ institutionName, ...props }, ref) => {
const {
formState: { defaultValues },
control,
watch,
institutionsFieldArray,
} = useFormContext();
const institutionFields =
institutionsFieldArray.fields[getInstitutionIndex(institutionName)];
const institutionDefaultValues =
defaultValues.institutions[getInstitutionIndex(institutionName)];
const isDeleted = false; /* watch(`${institutionName}.isDeleted`); */
const isDeleted = watch(`${institutionName}.isDeleted`);
const institutionCurrentValues = watch(institutionName);
const isChanged =
JSON.stringify(institutionDefaultValues) !==
JSON.stringify(institutionCurrentValues);
const isNew = institutionFields.name === "";
const state = isNew ? "new" : isChanged ? "updated" : null;
const name =
useWatch({
control,
name: `${institutionName}.name`,
}) || "New Institution";
const name = watch(`${institutionName}.name`) || "New Institution";

return (
<Tab
Expand Down

0 comments on commit 22a67fe

Please sign in to comment.