diff --git a/src/api/index.ts b/src/api/index.ts index f9b4b14..941d772 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,5 +1,5 @@ import axios from 'axios'; -import { Bill, BillFormType } from '../types/bill'; +import { Bill, BillFormType, billFrom } from '../types/bill'; const BASE_URL = process.env.REACT_APP_API_URL; const client = axios.create({ baseURL: BASE_URL }); @@ -29,22 +29,6 @@ export const updateBill = async (id: number, data: BillFormType): Promise - ({ - id: bill.id, - customers: bill.customers_qty, - end: bill.end_date, - name: bill.name, - paymentMethod: bill.payment_method, - paymentStatus: bill.payment_status, - phoneNumber: bill.phone_number, - platform: bill.platform, - price: bill.price, - room: bill.room, - start: bill.start_date, - taxes: bill.with_tax - } as Bill); - export const fetchOneBill = async (id: number): Promise> => { try { const { data } = await client.get(`/${id}`); diff --git a/src/types/bill/enums.ts b/src/types/bill/enums.ts new file mode 100644 index 0000000..a777c09 --- /dev/null +++ b/src/types/bill/enums.ts @@ -0,0 +1,26 @@ +export enum Room { + t2, + t3 +} + +export enum Platform { + web, + booking, + airbnb, + tripadvisor, + perso +} + +export enum PaymentMethod { + card, + cash, + cheque, + transfer +} + +export enum PaymentStatus { + pending, + canceled, + completed, + refund +} diff --git a/src/types/bill.ts b/src/types/bill/index.ts similarity index 52% rename from src/types/bill.ts rename to src/types/bill/index.ts index 7cbe1e1..1ff6c0c 100644 --- a/src/types/bill.ts +++ b/src/types/bill/index.ts @@ -1,3 +1,5 @@ +import { PaymentMethod, PaymentStatus, Platform, Room } from './enums'; + export type BillFormType = { name: string; phoneNumber: string; @@ -27,29 +29,18 @@ export interface Bill { paymentStatus: PaymentStatus; } -export enum Room { - t2, - t3 -} - -export enum Platform { - web, - booking, - airbnb, - tripadvisor, - perso -} - -export enum PaymentMethod { - card, - cash, - cheque, - transfer -} - -export enum PaymentStatus { - pending, - canceled, - completed, - refund -} +export const billFrom = (bill: any): Bill => + ({ + id: bill.id, + customers: bill.customers_qty, + end: bill.end_date, + name: bill.name, + paymentMethod: bill.payment_method, + paymentStatus: bill.payment_status, + phoneNumber: bill.phone_number, + platform: bill.platform, + price: bill.price, + room: bill.room, + start: bill.start_date, + taxes: bill.with_tax + } as Bill);