Skip to content

Commit

Permalink
remember password
Browse files Browse the repository at this point in the history
  • Loading branch information
karenyov committed Mar 24, 2023
1 parent 40cb088 commit 560f037
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/pages/history/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
IconButton as IconButtonBase,
useColorMode,
} from "@chakra-ui/react";
import { FiPlus, FiTrash2 } from "react-icons/fi";
import { FiTrash2 } from "react-icons/fi";

import Box from "@/components/Box";
import IconButton from "@/components/IconButton";
Expand Down
86 changes: 49 additions & 37 deletions src/pages/register/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import avatarlightImage from "../../assets/_light/avatar.png";
import { createRegister } from "@/services/register";
import { RegisterModel } from "@/models/register";
import { addCentsMarkCurrency } from "@/utils/addCentsMarkCurrency";
import useAuth from "@/hooks/useAuth";

interface FileProps {
name: string;
Expand All @@ -39,9 +40,7 @@ const formSchema = z.object({
salary: z.string({
required_error: "Digite o Salário",
}),
others: z.string({
required_error: "Digite Outros Valores",
}),
others: z.string().optional(),
});

type FormDataProps = z.infer<typeof formSchema>;
Expand All @@ -54,6 +53,8 @@ export default function Register() {

const [fileRegister, setFileRegister] = useState<FileProps>({} as FileProps);

const isAuthenticated = useAuth(true);

const {
control,
handleSubmit,
Expand All @@ -68,15 +69,17 @@ export default function Register() {
const register = {
userId: session?.user.id,
cell: data.cell.replace(/[^0-9]/g, ""),
others: Number(
others: data.others? Number(
data.others.replace("R$", "").replace(".", "").replace(",", ".")
),
) : 0,
salary: Number(
data.salary.replace("R$", "").replace(".", "").replace(",", ".")
),
photo: fileRegister.base64? fileRegister.base64
.replace("data:image/jpeg;base64,", "")
.replace("data:image/png;base64,", "") : "",
photo: fileRegister.base64
? fileRegister.base64
.replace("data:image/jpeg;base64,", "")
.replace("data:image/png;base64,", "")
: "",
} as RegisterModel;

const res = await createRegister(register);
Expand All @@ -88,7 +91,7 @@ export default function Register() {
});

router.push({
pathname: "/dashboard",
pathname: "/",
});
}

Expand Down Expand Up @@ -180,47 +183,56 @@ export default function Register() {
control={control}
name="cell"
render={({ field: { onChange, value } }) => (
<Input
size="md"
placeholder="Celular"
errorMessage={errors.cell?.message}
onChange={onChange}
as={InputMask}
mask="(**) *****-****"
/>
<VStack w="100%" alignItems="left">
<Text as="b">Celular</Text>
<Input
size="md"
placeholder="Celular"
errorMessage={errors.cell?.message}
onChange={onChange}
as={InputMask}
mask="(**) *****-****"
/>
</VStack>
)}
/>

<HStack w="100%" mt={5}>
<Controller
control={control}
name="others"
name="salary"
render={({ field: { onChange, value } }) => (
<Input
size="md"
placeholder="Outros"
errorMessage={errors.others?.message}
onChange={onChange}
as={MaskedInput}
mask={realMask}
value={addCentsMarkCurrency(value) || ""}
/>
<VStack w="100%" alignItems="left">
<Text as="b">Salário</Text>
<Input
size="md"
placeholder="Salário"
errorMessage={errors.salary?.message}
onChange={onChange}
as={MaskedInput}
mask={realMask}
value={addCentsMarkCurrency(value) || ""}
/>
</VStack>
)}
/>

<Controller
control={control}
name="salary"
name="others"
render={({ field: { onChange, value } }) => (
<Input
size="md"
placeholder="Salário"
errorMessage={errors.salary?.message}
onChange={onChange}
as={MaskedInput}
mask={realMask}
value={addCentsMarkCurrency(value) || ""}
/>
<VStack w="100%" alignItems="left">
<Text as="b">Outros</Text>
<Input
size="md"
placeholder="Outros"
errorMessage={errors.others?.message}
onChange={onChange}
as={MaskedInput}
mask={realMask}
value={addCentsMarkCurrency(value? value : "0") || ""}
/>
</VStack>
)}
/>
</HStack>
Expand Down
4 changes: 1 addition & 3 deletions src/pages/settings/index.tsx