teo.villanueva
teo.villanueva
TtRPC
Created by teo.villanueva on 5/25/2023 in #❓-help
Trpc refetches all of the queries when i run a mutation
also, im not performing any manual invalidation
19 replies
TtRPC
Created by teo.villanueva on 5/25/2023 in #❓-help
Trpc refetches all of the queries when i run a mutation
I also have this deployed to vercel
19 replies
TtRPC
Created by teo.villanueva on 5/25/2023 in #❓-help
Trpc refetches all of the queries when i run a mutation
If you want I can give you access to the codebase
19 replies
TtRPC
Created by teo.villanueva on 5/25/2023 in #❓-help
Trpc refetches all of the queries when i run a mutation
just checked with the component profiler and it doesnt look like it is remounting
19 replies
TtRPC
Created by teo.villanueva on 5/25/2023 in #❓-help
Trpc refetches all of the queries when i run a mutation
import { AddProductButton } from '@/components/add-product-button';
import { AdminPageHeader } from '@/components/admin-page-header';
import { ProductsTable } from '@/components/products-table';
import { HydrateClient } from '@/lib/trpc/client/hydrate-client';
import { rsc } from '@/shared/server-rsc/trpc';

export const metadata = {
title: 'Products',
};

export default async function AdminShopProductsPage({
params,
}: {
params: { shopSlug: string };
}) {
await rsc.product.all.fetch({ shopSlug: params.shopSlug });

const dehydratedState = await rsc.dehydrate();

return (
<HydrateClient state={dehydratedState}>
<AdminPageHeader heading="Products" headingRight={<AddProductButton />} />
<ProductsTable />
</HydrateClient>
);
}
import { AddProductButton } from '@/components/add-product-button';
import { AdminPageHeader } from '@/components/admin-page-header';
import { ProductsTable } from '@/components/products-table';
import { HydrateClient } from '@/lib/trpc/client/hydrate-client';
import { rsc } from '@/shared/server-rsc/trpc';

export const metadata = {
title: 'Products',
};

export default async function AdminShopProductsPage({
params,
}: {
params: { shopSlug: string };
}) {
await rsc.product.all.fetch({ shopSlug: params.shopSlug });

const dehydratedState = await rsc.dehydrate();

return (
<HydrateClient state={dehydratedState}>
<AdminPageHeader heading="Products" headingRight={<AddProductButton />} />
<ProductsTable />
</HydrateClient>
);
}
19 replies
TtRPC
Created by teo.villanueva on 5/25/2023 in #❓-help
Trpc refetches all of the queries when i run a mutation
This is my products page
19 replies
TtRPC
Created by teo.villanueva on 5/25/2023 in #❓-help
Trpc refetches all of the queries when i run a mutation
Im using the app dir with react server components
19 replies
TtRPC
Created by teo.villanueva on 5/25/2023 in #❓-help
Trpc refetches all of the queries when i run a mutation
This is how my react-query devtools look before running the mutation
19 replies
TtRPC
Created by teo.villanueva on 5/25/2023 in #❓-help
Trpc refetches all of the queries when i run a mutation
19 replies
TtRPC
Created by teo.villanueva on 5/25/2023 in #❓-help
Trpc refetches all of the queries when i run a mutation
This gets called when the form is submitted
19 replies
TtRPC
Created by teo.villanueva on 5/25/2023 in #❓-help
Trpc refetches all of the queries when i run a mutation
export function useUpdateShopForm(_args?: UseUpdateShopFormArgs) {
const { shop } = useShop();
const updateShopMutation = api.shop.update.useMutation({});

const updateShopForm = useZodForm(UpdateShopSchema, {
defaultValues: {
name: shop.name,
description: shop.description,
deliveryMethods: shop.deliveryMethods,
paymentMethods: shop.paymentMethods,
},
});

const onSubmit = useCallback(
async (input: UpdateShopSchema) => {
if (
Object.values(input.deliveryMethods).every(
(value) => value === false
) ||
Object.values(input.paymentMethods).every((value) => value === false)
) {
toast.error('At least one value must be checked.');
return;
}

const updatedShop = await updateShopMutation.mutateAsync({
shopSlug: shop.slug,
...input,
});

updateShopForm.reset({
name: updatedShop.name,
description: updatedShop.description,
deliveryMethods: updatedShop.deliveryMethods,
paymentMethods: updatedShop.paymentMethods,
});
},
[updateShopMutation, shop, updateShopForm]
);

return {
updateShopMutation,
updateShopForm,
loading: updateShopMutation.isLoading,
handleSubmit: updateShopForm.handleSubmit(onSubmit),
};
}
export function useUpdateShopForm(_args?: UseUpdateShopFormArgs) {
const { shop } = useShop();
const updateShopMutation = api.shop.update.useMutation({});

const updateShopForm = useZodForm(UpdateShopSchema, {
defaultValues: {
name: shop.name,
description: shop.description,
deliveryMethods: shop.deliveryMethods,
paymentMethods: shop.paymentMethods,
},
});

const onSubmit = useCallback(
async (input: UpdateShopSchema) => {
if (
Object.values(input.deliveryMethods).every(
(value) => value === false
) ||
Object.values(input.paymentMethods).every((value) => value === false)
) {
toast.error('At least one value must be checked.');
return;
}

const updatedShop = await updateShopMutation.mutateAsync({
shopSlug: shop.slug,
...input,
});

updateShopForm.reset({
name: updatedShop.name,
description: updatedShop.description,
deliveryMethods: updatedShop.deliveryMethods,
paymentMethods: updatedShop.paymentMethods,
});
},
[updateShopMutation, shop, updateShopForm]
);

return {
updateShopMutation,
updateShopForm,
loading: updateShopMutation.isLoading,
handleSubmit: updateShopForm.handleSubmit(onSubmit),
};
}
19 replies
TtRPC
Created by teo.villanueva on 5/25/2023 in #❓-help
Trpc refetches all of the queries when i run a mutation
Can some one help me please
19 replies