Skip to content

Commit

Permalink
Merge pull request #30 from Build-Squad/fix-api-call
Browse files Browse the repository at this point in the history
Fix package creation/update bug and add influencer
  • Loading branch information
varsha1305nav authored Dec 7, 2023
2 parents df06b5b + 962fe51 commit b25cffa
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/ui/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ export default function Home() {
// Authenticate user based on cookie present on the browser
const isAuthenticated = async () => {
try {
await axios.get(
const res = await axios.get(
process.env.NEXT_PUBLIC_BACKEND_URL + "is-authenticated/",
{
withCredentials: true,
}
);
console.log("User is authenticated:", res);
localStorage.setItem("user", JSON.stringify(res?.data?.data));
setIsUserAuthenticated(true);
} catch (e) {
setIsUserAuthenticated(false);
console.log("Error while authenticating:", e);
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/ui/app/profile/packages/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const Packages = () => {
}
);
if (isSuccess) {
setPackages(data?.data);
setPackages(data);
setPagination({
...pagination,
total_data_count: data?.pagination?.total_data_count,
Expand Down Expand Up @@ -259,7 +259,7 @@ const Packages = () => {
</Tooltip>
</Card>
</Grid>
{packages.map((item: PackageType) => (
{packages?.map((item: PackageType) => (
<Grid item xs={12} sm={6} md={4} lg={3} key={item.id}>
<Card
sx={{
Expand Down
4 changes: 2 additions & 2 deletions src/ui/app/profile/services/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const Services = () => {
}
);
if (isSuccess) {
setServices(data?.data);
setServices(data);
setPagination({
...pagination,
total_data_count: data?.pagination?.total_data_count,
Expand Down Expand Up @@ -280,7 +280,7 @@ const Services = () => {
</Tooltip>
</Card>
</Grid>
{services.map((service) => (
{services?.map((service) => (
<Grid item xs={12} sm={6} md={4} lg={3} key={service.id}>
<Card
sx={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ const CreateUpdatePackage = ({
setRefreshPage,
}: CreateUpdatePackageProps) => {
const [loading, setLoading] = React.useState<boolean>(false);
const [influecerId, setInfluencerId] = React.useState<string | null>(null);

const updatePackage = async (values: FormikValues) => {
try {
setLoading(true);
const { message, data, errors, isSuccess } = await putService(
`/packages/${packageItem?.id}/`,
values
{
...values,
influencer: influecerId,
}
);
if (isSuccess) {
notification(message);
Expand All @@ -71,7 +75,10 @@ const CreateUpdatePackage = ({
setLoading(true);
const { message, data, errors, isSuccess } = await postService(
"/packages/",
values
{
...values,
influencer: influecerId,
}
);
if (isSuccess) {
notification(message);
Expand Down Expand Up @@ -120,6 +127,14 @@ const CreateUpdatePackage = ({
}
}, [packageItem, open]);

useEffect(() => {
const user = localStorage.getItem("user");
if (user) {
const userObject = JSON.parse(user);
setInfluencerId(userObject?.user?.id);
}
}, []);

return (
<CustomModal open={open} setOpen={setOpen}>
<Grid container>
Expand Down
2 changes: 1 addition & 1 deletion src/ui/src/components/shared/customAutoComplete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const CustomAutoComplete = ({
page_number: pagination.current_page_number,
});
if (isSuccess) {
setOptions([...options, ...data.data]);
setOptions([...options, ...data]);
}
} catch (error) {
console.error("Failed to fetch options:", error);
Expand Down

0 comments on commit b25cffa

Please sign in to comment.