refresh api logout and login
This commit is contained in:
@@ -45,8 +45,7 @@ const Login = () => {
|
|||||||
setRefToken(res.data.refresh);
|
setRefToken(res.data.refresh);
|
||||||
setUser(form.getValues('username'));
|
setUser(form.getValues('username'));
|
||||||
router.push('/');
|
router.push('/');
|
||||||
queryClient.refetchQueries({ queryKey: ['product_list'] });
|
queryClient.refetchQueries();
|
||||||
queryClient.refetchQueries({ queryKey: ['get_me'] });
|
|
||||||
},
|
},
|
||||||
onError: () => {
|
onError: () => {
|
||||||
toast.error(t('Username yoki parol xato kiritildi'), {
|
toast.error(t('Username yoki parol xato kiritildi'), {
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ const CartPage = () => {
|
|||||||
const subtotal =
|
const subtotal =
|
||||||
cartItems.reduce((sum, item) => {
|
cartItems.reduce((sum, item) => {
|
||||||
if (!item.product.prices.length) return sum;
|
if (!item.product.prices.length) return sum;
|
||||||
const maxPrice = Math.max(
|
const maxPrice = Math.min(
|
||||||
...item.product.prices.map((p) => Number(p.price)),
|
...item.product.prices.map((p) => Number(p.price)),
|
||||||
);
|
);
|
||||||
return sum + maxPrice * (quantities[item.id] || item.quantity);
|
return sum + maxPrice * (quantities[item.id] || item.quantity);
|
||||||
@@ -228,7 +228,7 @@ const CartPage = () => {
|
|||||||
<div className="flex items-center gap-2 mb-3 max-lg:flex-col max-lg:items-start max-lg:gap-1">
|
<div className="flex items-center gap-2 mb-3 max-lg:flex-col max-lg:items-start max-lg:gap-1">
|
||||||
<span className="text-blue-600 font-bold text-xl">
|
<span className="text-blue-600 font-bold text-xl">
|
||||||
{formatPrice(
|
{formatPrice(
|
||||||
Math.max(
|
Math.min(
|
||||||
...item.product.prices.map((p) => Number(p.price)),
|
...item.product.prices.map((p) => Number(p.price)),
|
||||||
),
|
),
|
||||||
true,
|
true,
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ const OrderPage = () => {
|
|||||||
if (item.product.prices.length === 0) return sum; // narx yo'q bo'lsa qo'shmaymiz
|
if (item.product.prices.length === 0) return sum; // narx yo'q bo'lsa qo'shmaymiz
|
||||||
|
|
||||||
// Eng yuqori narxni olish
|
// Eng yuqori narxni olish
|
||||||
const maxPrice = Math.max(
|
const maxPrice = Math.min(
|
||||||
...item.product.prices.map((p) => Number(p.price)),
|
...item.product.prices.map((p) => Number(p.price)),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -587,7 +587,7 @@ const OrderPage = () => {
|
|||||||
{item.quantity} x{' '}
|
{item.quantity} x{' '}
|
||||||
{formatPrice(
|
{formatPrice(
|
||||||
item.product.prices.length !== 0
|
item.product.prices.length !== 0
|
||||||
? Math.max(
|
? Math.min(
|
||||||
...item.product.prices.map((p) =>
|
...item.product.prices.map((p) =>
|
||||||
Number(p.price),
|
Number(p.price),
|
||||||
),
|
),
|
||||||
@@ -599,7 +599,7 @@ const OrderPage = () => {
|
|||||||
<p className="font-semibold text-sm">
|
<p className="font-semibold text-sm">
|
||||||
{formatPrice(
|
{formatPrice(
|
||||||
item.product.prices.length !== 0
|
item.product.prices.length !== 0
|
||||||
? Math.max(
|
? Math.min(
|
||||||
...item.product.prices.map((p) =>
|
...item.product.prices.map((p) =>
|
||||||
Number(p.price),
|
Number(p.price),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ const ProductDetail = () => {
|
|||||||
setQuantity((q) => {
|
setQuantity((q) => {
|
||||||
let next = q - STEP;
|
let next = q - STEP;
|
||||||
if (isGram) next = Math.floor(next / STEP) * STEP;
|
if (isGram) next = Math.floor(next / STEP) * STEP;
|
||||||
return Math.max(MIN_QTY, next);
|
return Math.min(MIN_QTY, next);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -115,10 +115,7 @@ const Profile = () => {
|
|||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
queryClient.refetchQueries({ queryKey: ['product_list'] });
|
queryClient.refetchQueries();
|
||||||
queryClient.refetchQueries({ queryKey: ['favourite_product'] });
|
|
||||||
queryClient.refetchQueries({ queryKey: ['cart_items'] });
|
|
||||||
queryClient.refetchQueries({ queryKey: ['search'] });
|
|
||||||
setCartId(null);
|
setCartId(null);
|
||||||
removeToken();
|
removeToken();
|
||||||
router.push('/');
|
router.push('/');
|
||||||
@@ -152,14 +149,8 @@ const Profile = () => {
|
|||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
queryClient.refetchQueries({ queryKey: ['product_list'] });
|
queryClient.refetchQueries();
|
||||||
queryClient.refetchQueries({ queryKey: ['cart_items'] });
|
|
||||||
queryClient.refetchQueries({
|
|
||||||
queryKey: ['favourite_product'],
|
|
||||||
});
|
|
||||||
queryClient.refetchQueries({ queryKey: ['search'] });
|
|
||||||
removeToken();
|
removeToken();
|
||||||
setCartId(null);
|
|
||||||
router.push('/');
|
router.push('/');
|
||||||
}}
|
}}
|
||||||
className="w-9 h-9 md:w-10 md:h-10"
|
className="w-9 h-9 md:w-10 md:h-10"
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ const getPages = (current: number, total: number) => {
|
|||||||
pages.push('dots');
|
pages.push('dots');
|
||||||
}
|
}
|
||||||
|
|
||||||
const start = Math.max(2, current - 1);
|
const start = Math.min(2, current - 1);
|
||||||
const end = Math.min(total - 1, current + 1);
|
const end = Math.min(total - 1, current + 1);
|
||||||
|
|
||||||
for (let i = start; i <= end; i++) {
|
for (let i = start; i <= end; i++) {
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ export function ProductCard({
|
|||||||
{product.prices.length > 0 && (
|
{product.prices.length > 0 && (
|
||||||
<p className="text-lg font-bold">
|
<p className="text-lg font-bold">
|
||||||
{formatPrice(
|
{formatPrice(
|
||||||
Math.max(...product.prices.map((p) => Number(p.price))),
|
Math.min(...product.prices.map((p) => Number(p.price))),
|
||||||
true,
|
true,
|
||||||
)}
|
)}
|
||||||
<span className="text-sm text-slate-500 ml-1">
|
<span className="text-sm text-slate-500 ml-1">
|
||||||
|
|||||||
@@ -130,7 +130,9 @@ export const SearchResult = ({ query }: SearchResultProps) => {
|
|||||||
</p>
|
</p>
|
||||||
{price && (
|
{price && (
|
||||||
<p className="text-sm font-semibold text-[#57A595] mt-1">
|
<p className="text-sm font-semibold text-[#57A595] mt-1">
|
||||||
{formatPrice(price)}
|
{formatPrice(
|
||||||
|
Math.min(...product.prices.map((p) => Number(p.price))),
|
||||||
|
)}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user