Retrieving user.id to HBFormPage
This commit is contained in:
@@ -7,6 +7,8 @@ import config from "../config";
|
|||||||
import NextUIFormikInput from "../components/NextUIFormikInput";
|
import NextUIFormikInput from "../components/NextUIFormikInput";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import InsertImage from "../components/InsertImage";
|
import InsertImage from "../components/InsertImage";
|
||||||
|
import { retrieveUserInformation } from "../security/users";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
const validationSchema = Yup.object({
|
const validationSchema = Yup.object({
|
||||||
electricalBill: Yup.number()
|
electricalBill: Yup.number()
|
||||||
@@ -32,17 +34,8 @@ const validationSchema = Yup.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export default function HBFormPage() {
|
export default function HBFormPage() {
|
||||||
const navigate = useNavigate();
|
const [userId, setUserId] = useState(null);
|
||||||
|
const [initialValues, setInitialValues] = useState({
|
||||||
const initialValues: {
|
|
||||||
id: string;
|
|
||||||
electricalBill: string;
|
|
||||||
waterBill: string;
|
|
||||||
totalBill: string;
|
|
||||||
noOfDependents: string;
|
|
||||||
ebPicture: File | null;
|
|
||||||
wbPicture: File | null;
|
|
||||||
} = {
|
|
||||||
id: "",
|
id: "",
|
||||||
electricalBill: "",
|
electricalBill: "",
|
||||||
waterBill: "",
|
waterBill: "",
|
||||||
@@ -50,7 +43,31 @@ export default function HBFormPage() {
|
|||||||
noOfDependents: "",
|
noOfDependents: "",
|
||||||
ebPicture: null,
|
ebPicture: null,
|
||||||
wbPicture: null,
|
wbPicture: null,
|
||||||
};
|
userId: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const getUserInformation = async () => {
|
||||||
|
try {
|
||||||
|
const user = await retrieveUserInformation(); // Get the user ID
|
||||||
|
setUserId(user.id); // Set the user ID in the state
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
getUserInformation();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (userId) {
|
||||||
|
setInitialValues((prevInitialValues) => ({
|
||||||
|
...prevInitialValues,
|
||||||
|
userId,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}, [userId]);
|
||||||
|
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const handleSubmit = async (
|
const handleSubmit = async (
|
||||||
values: any,
|
values: any,
|
||||||
@@ -70,6 +87,10 @@ export default function HBFormPage() {
|
|||||||
formData.append("wbPicture", values.wbPicture);
|
formData.append("wbPicture", values.wbPicture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (userId != null) {
|
||||||
|
formData.append("userId", userId);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
config.serverAddress + "/hbcform",
|
config.serverAddress + "/hbcform",
|
||||||
|
|||||||
@@ -34,9 +34,14 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
type: DataTypes.BLOB("long"),
|
type: DataTypes.BLOB("long"),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
},
|
},
|
||||||
|
userId: {
|
||||||
|
type: DataTypes.UUID,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
tableName: 'hbcform'
|
tableName: "hbcform",
|
||||||
|
timestamps: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
return HBCform;
|
return HBCform;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user