Compare commits
2 Commits
features/p
...
c4439e779f
| Author | SHA1 | Date | |
|---|---|---|---|
| c4439e779f | |||
| b512aef63d |
@ -54,7 +54,6 @@ export default function ContactRecordsList() {
|
||||
|
||||
// State for data
|
||||
const [contactRecords, setContactRecords] = useState<ContactRecord[]>([]);
|
||||
const [customers, setCustomers] = useState<Customer[]>([]);
|
||||
const [pagination, setPagination] = useState<PaginationInfo>({
|
||||
page: initialPage,
|
||||
pageSize: initialPageSize,
|
||||
@ -64,25 +63,6 @@ export default function ContactRecordsList() {
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
// Fetch customers for the filter dropdown
|
||||
useEffect(() => {
|
||||
const fetchCustomers = async () => {
|
||||
try {
|
||||
const response = await fetch('/api/customers');
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch customers');
|
||||
}
|
||||
const data = await response.json();
|
||||
setCustomers(data);
|
||||
} catch (err) {
|
||||
console.error('Error fetching customers:', err);
|
||||
setError(err instanceof Error ? err.message : 'An error occurred');
|
||||
}
|
||||
};
|
||||
|
||||
fetchCustomers();
|
||||
}, []);
|
||||
|
||||
// Fetch contact records with filters and pagination
|
||||
useEffect(() => {
|
||||
const fetchContactRecords = async () => {
|
||||
@ -173,22 +153,17 @@ export default function ContactRecordsList() {
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-4">
|
||||
<div>
|
||||
<label htmlFor="customerId" className="block text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||
Customer
|
||||
Search Customer
|
||||
</label>
|
||||
<select
|
||||
<input
|
||||
type="text"
|
||||
id="customerId"
|
||||
name="customerId"
|
||||
value={customerId}
|
||||
onChange={(e) => setCustomerId(e.target.value)}
|
||||
placeholder="Search customer..."
|
||||
className="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md dark:bg-gray-800 dark:border-gray-700 dark:text-gray-200"
|
||||
>
|
||||
<option value="">All Customers</option>
|
||||
{customers.map((customer) => (
|
||||
<option key={customer.id} value={customer.id}>
|
||||
{customer.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="contactType" className="block text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||
|
||||
@ -26,6 +26,7 @@ export default function ContactRecordList({ customerId }: ContactRecordListProps
|
||||
|
||||
// Function to fetch contact records
|
||||
const fetchContactRecords = async () => {
|
||||
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const response = await fetch(`/api/contact-records?customerId=${customerId}`);
|
||||
@ -35,7 +36,7 @@ export default function ContactRecordList({ customerId }: ContactRecordListProps
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
setContactRecords(data);
|
||||
setContactRecords(data.data);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'An error occurred while fetching contact records');
|
||||
} finally {
|
||||
|
||||
@ -7,6 +7,7 @@ export async function GET(request: NextRequest) {
|
||||
const dataSource = await getDataSource();
|
||||
const contactRecordRepository = dataSource.getRepository(ContactRecord);
|
||||
|
||||
|
||||
// Get query parameters
|
||||
const url = new URL(request.url);
|
||||
const customerId = url.searchParams.get('customerId');
|
||||
|
||||
Reference in New Issue
Block a user