@philipe1993/list-color 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.tsx +2 -0
 - package/package.json +9 -6
 - package/services/ColorService.ts +56 -0
 - package/store/colorStore.ts +135 -0
 - package/types/Color.ts +10 -0
 
    
        package/index.tsx
    ADDED
    
    
    
        package/package.json
    CHANGED
    
    | 
         @@ -2,16 +2,19 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
                "name": "@philipe1993/list-color",
         
     | 
| 
       3 
3 
     | 
    
         
             
                "main": "src/index.js",
         
     | 
| 
       4 
4 
     | 
    
         
             
                "types": "src/index.d.ts",
         
     | 
| 
       5 
     | 
    
         
            -
                "version": "1.0. 
     | 
| 
      
 5 
     | 
    
         
            +
                "version": "1.0.1",
         
     | 
| 
       6 
6 
     | 
    
         
             
                "peerDependencies": {
         
     | 
| 
       7 
     | 
    
         
            -
                    "react": "^18.3.1",
         
     | 
| 
       8 
     | 
    
         
            -
                    "mobx": "^6.13.5",
         
     | 
| 
       9 
     | 
    
         
            -
                    "axios": "^1.7.7",
         
     | 
| 
       10 
7 
     | 
    
         
             
                    "antd": "^5.22.0",
         
     | 
| 
       11 
     | 
    
         
            -
                    " 
     | 
| 
       12 
     | 
    
         
            -
                    "mobx 
     | 
| 
      
 8 
     | 
    
         
            +
                    "axios": "^1.7.7",
         
     | 
| 
      
 9 
     | 
    
         
            +
                    "mobx": "^6.13.5",
         
     | 
| 
      
 10 
     | 
    
         
            +
                    "mobx-react-lite": "^4.0.7",
         
     | 
| 
      
 11 
     | 
    
         
            +
                    "react": "^18.3.1",
         
     | 
| 
      
 12 
     | 
    
         
            +
                    "tailwindcss": "^3.4.12"
         
     | 
| 
       13 
13 
     | 
    
         
             
                },
         
     | 
| 
       14 
14 
     | 
    
         
             
                "devDependencies": {
         
     | 
| 
       15 
15 
     | 
    
         
             
                    "typescript": "^5.6.2"
         
     | 
| 
      
 16 
     | 
    
         
            +
                },
         
     | 
| 
      
 17 
     | 
    
         
            +
                "dependencies": {
         
     | 
| 
      
 18 
     | 
    
         
            +
                    "@philipe1993/shared": "^1.0.2"
         
     | 
| 
       16 
19 
     | 
    
         
             
                }
         
     | 
| 
       17 
20 
     | 
    
         
             
            }
         
     | 
| 
         @@ -0,0 +1,56 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
             
     | 
| 
      
 2 
     | 
    
         
            +
            import URLS from '../../shared/src/config/urls';
         
     | 
| 
      
 3 
     | 
    
         
            +
            import { Color } from '../types/Color';
         
     | 
| 
      
 4 
     | 
    
         
            +
            import { getAPIInstance } from "@philipe1993/shared";
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            const api = getAPIInstance();
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            class ColorService {
         
     | 
| 
      
 10 
     | 
    
         
            +
                async getList(params: any): Promise<any> {
         
     | 
| 
      
 11 
     | 
    
         
            +
                    try {
         
     | 
| 
      
 12 
     | 
    
         
            +
                        const response = await api.get(`${URLS.COLORS}/search`, { params });
         
     | 
| 
      
 13 
     | 
    
         
            +
                        return response; // Retorna a resposta da API
         
     | 
| 
      
 14 
     | 
    
         
            +
                    } catch (e) {
         
     | 
| 
      
 15 
     | 
    
         
            +
                        return { error: "Erro ao trazer listagem" }; // Retorna um objeto de erro
         
     | 
| 
      
 16 
     | 
    
         
            +
                    }
         
     | 
| 
      
 17 
     | 
    
         
            +
                }
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                async createColor(color: Color): Promise<any> {
         
     | 
| 
      
 20 
     | 
    
         
            +
                    try {
         
     | 
| 
      
 21 
     | 
    
         
            +
                        const response = await api.post(`${URLS.COLORS}`, color);
         
     | 
| 
      
 22 
     | 
    
         
            +
                        return response; // Retorna a resposta da API
         
     | 
| 
      
 23 
     | 
    
         
            +
                    } catch (error) {
         
     | 
| 
      
 24 
     | 
    
         
            +
                        return { error: "Erro ao cadastrar", details: error };  // Retorna um objeto de erro
         
     | 
| 
      
 25 
     | 
    
         
            +
                    }
         
     | 
| 
      
 26 
     | 
    
         
            +
                }
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                async editColor(color: Color, uuid: string | undefined): Promise<any> {
         
     | 
| 
      
 29 
     | 
    
         
            +
                    try {
         
     | 
| 
      
 30 
     | 
    
         
            +
                        const response = await api.put(`${URLS.COLORS}/${uuid}`, color);
         
     | 
| 
      
 31 
     | 
    
         
            +
                        return response; // Retorna a resposta da API
         
     | 
| 
      
 32 
     | 
    
         
            +
                    } catch (error) {
         
     | 
| 
      
 33 
     | 
    
         
            +
                        return { error: "Erro ao cadastrar", details: error }; // Retorna um objeto de erro
         
     | 
| 
      
 34 
     | 
    
         
            +
                    }
         
     | 
| 
      
 35 
     | 
    
         
            +
                }
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                async getColorByUuid(uuid: any): Promise<any> {
         
     | 
| 
      
 38 
     | 
    
         
            +
                    try {
         
     | 
| 
      
 39 
     | 
    
         
            +
                        const response = await api.get(`${URLS.COLORS}/${uuid}`);
         
     | 
| 
      
 40 
     | 
    
         
            +
                        return response; // Retorna a resposta da API
         
     | 
| 
      
 41 
     | 
    
         
            +
                    } catch (e) {
         
     | 
| 
      
 42 
     | 
    
         
            +
                        return { error: "Erro ao buscar dados" }; // Retorna um objeto de erro
         
     | 
| 
      
 43 
     | 
    
         
            +
                    }
         
     | 
| 
      
 44 
     | 
    
         
            +
                }
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                async deleteColor(uuid: any): Promise<any> {
         
     | 
| 
      
 47 
     | 
    
         
            +
                    try {
         
     | 
| 
      
 48 
     | 
    
         
            +
                        const response = await api.delete(`${URLS.COLORS}/${uuid}`);
         
     | 
| 
      
 49 
     | 
    
         
            +
                        return response; // Retorna a resposta da API
         
     | 
| 
      
 50 
     | 
    
         
            +
                    } catch (e) {
         
     | 
| 
      
 51 
     | 
    
         
            +
                        return { error: "Erro ao deletar" }; // Retorna um objeto de erro
         
     | 
| 
      
 52 
     | 
    
         
            +
                    }
         
     | 
| 
      
 53 
     | 
    
         
            +
                }
         
     | 
| 
      
 54 
     | 
    
         
            +
            }
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
            export default new ColorService();
         
     | 
| 
         @@ -0,0 +1,135 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            import { message } from 'antd';
         
     | 
| 
      
 2 
     | 
    
         
            +
            import { makeAutoObservable, runInAction } from 'mobx';
         
     | 
| 
      
 3 
     | 
    
         
            +
            import { Color } from '../types/Color';
         
     | 
| 
      
 4 
     | 
    
         
            +
            import ColorService from '../services/ColorService';
         
     | 
| 
      
 5 
     | 
    
         
            +
            import { DEFAULT_PAGE_SIZE } from "@philipe1993/shared";
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            class ColorStore {
         
     | 
| 
      
 8 
     | 
    
         
            +
                loading: boolean = false;
         
     | 
| 
      
 9 
     | 
    
         
            +
                colorList: Color[] = [];
         
     | 
| 
      
 10 
     | 
    
         
            +
                colorSelectList: any;
         
     | 
| 
      
 11 
     | 
    
         
            +
                sort?: string = 'created,desc';
         
     | 
| 
      
 12 
     | 
    
         
            +
                totalPages: number = 0;
         
     | 
| 
      
 13 
     | 
    
         
            +
                color: Color | undefined;
         
     | 
| 
      
 14 
     | 
    
         
            +
                page: number = 0;
         
     | 
| 
      
 15 
     | 
    
         
            +
                totalElements: number = 0;
         
     | 
| 
      
 16 
     | 
    
         
            +
                size: number = DEFAULT_PAGE_SIZE;
         
     | 
| 
      
 17 
     | 
    
         
            +
                defaultparams = {
         
     | 
| 
      
 18 
     | 
    
         
            +
                    size: DEFAULT_PAGE_SIZE,
         
     | 
| 
      
 19 
     | 
    
         
            +
                    page: 0,
         
     | 
| 
      
 20 
     | 
    
         
            +
                    sort: 'created,desc',
         
     | 
| 
      
 21 
     | 
    
         
            +
                    search: '',
         
     | 
| 
      
 22 
     | 
    
         
            +
                }
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                reset() {
         
     | 
| 
      
 25 
     | 
    
         
            +
                    this.color = undefined;
         
     | 
| 
      
 26 
     | 
    
         
            +
                    this.colorList = [];
         
     | 
| 
      
 27 
     | 
    
         
            +
                    this.colorSelectList = [];
         
     | 
| 
      
 28 
     | 
    
         
            +
                }
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                constructor() {
         
     | 
| 
      
 31 
     | 
    
         
            +
                    makeAutoObservable(this);
         
     | 
| 
      
 32 
     | 
    
         
            +
                }
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                async getList(params: any) {
         
     | 
| 
      
 35 
     | 
    
         
            +
                    this.loading = true;
         
     | 
| 
      
 36 
     | 
    
         
            +
                    const response = await ColorService.getList(params);
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                    runInAction(() => {
         
     | 
| 
      
 39 
     | 
    
         
            +
                        if (!response.error) {
         
     | 
| 
      
 40 
     | 
    
         
            +
                            this.colorList = response.data.content;
         
     | 
| 
      
 41 
     | 
    
         
            +
                            this.totalPages = response.data.totalPages;
         
     | 
| 
      
 42 
     | 
    
         
            +
                            this.page = response.data.number;
         
     | 
| 
      
 43 
     | 
    
         
            +
                            this.totalElements = response.data.totalElements;
         
     | 
| 
      
 44 
     | 
    
         
            +
                            this.size = response.data.size;
         
     | 
| 
      
 45 
     | 
    
         
            +
                        }
         
     | 
| 
      
 46 
     | 
    
         
            +
                        this.loading = false;
         
     | 
| 
      
 47 
     | 
    
         
            +
                    });
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                    return response;
         
     | 
| 
      
 50 
     | 
    
         
            +
                }
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                async createColor(color: Color) {
         
     | 
| 
      
 53 
     | 
    
         
            +
                    this.loading = true;
         
     | 
| 
      
 54 
     | 
    
         
            +
                    const response = await ColorService.createColor(color);
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                    runInAction(() => {
         
     | 
| 
      
 57 
     | 
    
         
            +
                        if (response.error) {
         
     | 
| 
      
 58 
     | 
    
         
            +
                            message.error(response?.details?.response?.data?.message);
         
     | 
| 
      
 59 
     | 
    
         
            +
                            this.color = color;
         
     | 
| 
      
 60 
     | 
    
         
            +
                        } else {
         
     | 
| 
      
 61 
     | 
    
         
            +
                            message.success('Cor cadastrado com sucesso!');
         
     | 
| 
      
 62 
     | 
    
         
            +
                        }
         
     | 
| 
      
 63 
     | 
    
         
            +
                        this.loading = false;
         
     | 
| 
      
 64 
     | 
    
         
            +
                    });
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                    return response;
         
     | 
| 
      
 67 
     | 
    
         
            +
                }
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                async editColor(color: Color, uuid: string | undefined) {
         
     | 
| 
      
 70 
     | 
    
         
            +
                    this.loading = true;
         
     | 
| 
      
 71 
     | 
    
         
            +
                    const response = await ColorService.editColor(color, uuid);
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                    runInAction(() => {
         
     | 
| 
      
 74 
     | 
    
         
            +
                        if (response.error) {
         
     | 
| 
      
 75 
     | 
    
         
            +
                            message.error(response?.details?.response?.data?.message);
         
     | 
| 
      
 76 
     | 
    
         
            +
                            this.color = color;
         
     | 
| 
      
 77 
     | 
    
         
            +
                        } else {
         
     | 
| 
      
 78 
     | 
    
         
            +
                            message.success('Cor editado com sucesso!');
         
     | 
| 
      
 79 
     | 
    
         
            +
                        }
         
     | 
| 
      
 80 
     | 
    
         
            +
                        this.loading = false;
         
     | 
| 
      
 81 
     | 
    
         
            +
                    });
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                    return response;
         
     | 
| 
      
 84 
     | 
    
         
            +
                }
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                async getColorByUuid(uuid: string) {
         
     | 
| 
      
 87 
     | 
    
         
            +
                    this.loading = true;
         
     | 
| 
      
 88 
     | 
    
         
            +
                    const response = await ColorService.getColorByUuid(uuid);
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                    runInAction(() => {
         
     | 
| 
      
 91 
     | 
    
         
            +
                        if (response.error) {
         
     | 
| 
      
 92 
     | 
    
         
            +
                            message.error('Erro ao buscar Cor');
         
     | 
| 
      
 93 
     | 
    
         
            +
                            return;
         
     | 
| 
      
 94 
     | 
    
         
            +
                        }
         
     | 
| 
      
 95 
     | 
    
         
            +
                        this.color = response.data;
         
     | 
| 
      
 96 
     | 
    
         
            +
                        this.loading = false;
         
     | 
| 
      
 97 
     | 
    
         
            +
                    });
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                    return response;
         
     | 
| 
      
 100 
     | 
    
         
            +
                }
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
                async deleteColor(uuid: string) {
         
     | 
| 
      
 103 
     | 
    
         
            +
                    this.loading = true;
         
     | 
| 
      
 104 
     | 
    
         
            +
                    const response = await ColorService.deleteColor(uuid);
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
                    runInAction(() => {
         
     | 
| 
      
 107 
     | 
    
         
            +
                        if (response.error) {
         
     | 
| 
      
 108 
     | 
    
         
            +
                            message.error('Erro ao deletar Cor');
         
     | 
| 
      
 109 
     | 
    
         
            +
                        } else {
         
     | 
| 
      
 110 
     | 
    
         
            +
                            message.success('Cor deletado com sucesso!');
         
     | 
| 
      
 111 
     | 
    
         
            +
                            this.color = undefined;
         
     | 
| 
      
 112 
     | 
    
         
            +
                        }
         
     | 
| 
      
 113 
     | 
    
         
            +
                        this.loading = false;
         
     | 
| 
      
 114 
     | 
    
         
            +
                    });
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
                    return response;
         
     | 
| 
      
 117 
     | 
    
         
            +
                }
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
                async deleteColorAll(uuid: string) {
         
     | 
| 
      
 120 
     | 
    
         
            +
                    this.loading = true;
         
     | 
| 
      
 121 
     | 
    
         
            +
                    const response = await ColorService.deleteColor(uuid);
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
                    runInAction(() => {
         
     | 
| 
      
 124 
     | 
    
         
            +
                        if (!response.error) {
         
     | 
| 
      
 125 
     | 
    
         
            +
                            this.color = undefined;
         
     | 
| 
      
 126 
     | 
    
         
            +
                        }
         
     | 
| 
      
 127 
     | 
    
         
            +
                        this.loading = false;
         
     | 
| 
      
 128 
     | 
    
         
            +
                    });
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
                    return response;
         
     | 
| 
      
 131 
     | 
    
         
            +
                }
         
     | 
| 
      
 132 
     | 
    
         
            +
            }
         
     | 
| 
      
 133 
     | 
    
         
            +
             
     | 
| 
      
 134 
     | 
    
         
            +
            const colorStore = new ColorStore();
         
     | 
| 
      
 135 
     | 
    
         
            +
            export default colorStore;
         
     |