fix(clinic): render the real insurer logo on the clinic page

The component read item.logo[0].url, a shape the current API never sends, so
every insurer rendered the same placeholder. It now reads logo_url and runs it
through imageUrl(), since the API returns a path relative to its own host. The
old shape is still accepted for records that carry it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hamed
2026-08-19 23:34:43 +03:30
co-authored by Claude Opus 5
parent 179a6d5163
commit 9dec4fde4a
2 changed files with 38 additions and 1 deletions
@@ -1,6 +1,7 @@
"use client"; "use client";
import CustomLoading from "@/app/component/loading/Custom"; import CustomLoading from "@/app/component/loading/Custom";
import ArrowLeftList from "@/components/icons/ArrowLeftList"; import ArrowLeftList from "@/components/icons/ArrowLeftList";
import { imageUrl } from "@/helper";
import { Button } from "@mui/material"; import { Button } from "@mui/material";
import Image from "next/image"; import Image from "next/image";
import { useRef, useEffect, useState } from "react"; import { useRef, useEffect, useState } from "react";
@@ -64,8 +65,10 @@ function ListBime({ data }) {
className="p-[16px] border border-[#EFEFEF] h-[175px] flex flex-col items-center justify-center gap-[20px]" className="p-[16px] border border-[#EFEFEF] h-[175px] flex flex-col items-center justify-center gap-[20px]"
style={{ minWidth: itemWidth }} style={{ minWidth: itemWidth }}
> >
{/* `logo_url` مسیر نسبی روی خودِ API است و باید با دامنهٔ API کامل شود.
شکل قدیمی `logo[0].url` برای رکوردهای قدیمی نگه داشته شده. */}
<Image <Image
src={item.logo?.[0]?.url || "/assets/images/logo.png"} src={imageUrl(item.logo_url || item.logo?.[0]?.url, "/assets/images/logo.png")}
height={92} height={92}
width={92} width={92}
alt="bime" alt="bime"
@@ -0,0 +1,34 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen } from '@testing-library/react';
import ListBime from './ListBime';
// next/image به src خام دست نمی‌زند تا بشود آن را assert کرد.
vi.mock('next/image', () => ({
default: ({ src, alt }) => <img src={src} alt={alt} />,
}));
const LOGO = '/uploads/insurances/logo/2026-08/tamin.png';
beforeEach(() => {
process.env.NEXT_PUBLIC_API_URL = 'https://api.example.ir';
});
describe('ListBime', () => {
it('لوگوی بیمه را با دامنهٔ API کامل می‌کند', () => {
render(<ListBime data={{ list_bime: [{ name: 'تامین اجتماعی', logo_url: LOGO }] }} />);
expect(screen.getByAltText('bime')).toHaveAttribute('src', `https://api.example.ir${LOGO}`);
});
it('شکل قدیمی logo[0].url هنوز کار می‌کند', () => {
render(<ListBime data={{ list_bime: [{ name: 'بیمه ایران', logo: [{ url: LOGO }] }] }} />);
expect(screen.getByAltText('bime')).toHaveAttribute('src', `https://api.example.ir${LOGO}`);
});
it('بیمهٔ بدون لوگو به تصویر پیش‌فرض می‌افتد', () => {
render(<ListBime data={{ list_bime: [{ name: 'بیمه بی‌لوگو' }] }} />);
expect(screen.getByAltText('bime')).toHaveAttribute('src', '/assets/images/logo.png');
});
});