diff --git a/.eslintrc.json b/.eslintrc.json index baea138..406a9f3 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -25,6 +25,7 @@ "@typescript-eslint/no-explicit-any": "off" }, "ignorePatterns": [ - "*.js" + "*.js", + "*gen*" ] } diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..bbbbc84 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,34 @@ +name: Build +on: + push: + branches: + - '*' + - '!main' + pull_request: + branches: + - '*' + - '!main' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Use Node.js 18.x + uses: actions/setup-node@v1 + with: + node-version: 18.x + - name: Install Dependencies + run: yarn --silent + - name: Generate OpenAPI + run: | + yarn gen-api + - name: Build and Test + run: | + yarn build + + - name: Archive Artifacts + uses: actions/upload-artifact@v2 + with: + name: build + path: build diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index befcd00..e9a30e3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,4 +75,4 @@ jobs: prerelease: false allowUpdates: true bodyFile: CHANGELOG.md - tag: v1.0.0 \ No newline at end of file + tag: v1.1.0 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 05a0e77..32bb749 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,3 @@ # Changelog -Here we will write every update about this project \ No newline at end of file +- Changed SMS to API \ No newline at end of file diff --git a/openapi-config.ts b/openapi-config.ts index 4da5e1f..bae25fd 100644 --- a/openapi-config.ts +++ b/openapi-config.ts @@ -4,13 +4,13 @@ const config: ConfigFile = { schemaFile: './openapi.yaml', apiFile: './src/service/empty.api.ts', apiImport: 'emptySplitApi', - outputFile: './src/store/sms.gen.api.ts', + outputFile: './src/store/api.gen.api.ts', outputFiles: { - './src/store/sms.gen.api.ts': { - filterEndpoints: (operationName, operationDefinition) => operationDefinition.path.startsWith('/sms'), + './src/store/api.gen.api.ts': { + filterEndpoints: (operationName, operationDefinition) => operationDefinition.path.startsWith('/api'), }, }, - exportName: 'smsApi', + exportName: 'apiApi', hooks: true, } diff --git a/openapi.yaml b/openapi.yaml index e0de02d..f1dcb5b 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -1,8 +1,8 @@ openapi: 3.0.3 info: - title: SMS API Receiver + title: API Receiver description: |- - This is a description for the application SMS API which would mainly be a docker app. What is does, is simply a CRUD (without U) with JSON data on requests objects. So the backend is going to persist the whole request, even path and parameters. + This is a description for the application API which would mainly be a docker app. What is does, is simply a CRUD (without U) with JSON data on requests objects. So the backend is going to persist the whole request, even path and parameters. contact: email: dev@ssegning.com license: @@ -15,35 +15,35 @@ externalDocs: servers: - url: http://localhost:3000 tags: - - name: sms - description: Create, Delete and Read sms requests. + - name: api + description: Create, Delete and Read api requests. externalDocs: description: Find out more - url: https://blog.ssegning.com/tag/sms + url: https://blog.ssegning.com/tag/api - name: config description: Where we're going to add more config about the API (in the future) - name: user description: If we want to supports auth in a future, this might be helpful. paths: - /sms: + /api: post: tags: - - sms - summary: Add a new sms to the store - description: Add a new sms to the store - operationId: addSmsRequest + - api + summary: Add a new api to the store + description: Add a new api to the store + operationId: addApiRequest requestBody: - description: Create a new sms in the store + description: Create a new api in the store content: application/json: schema: - $ref: '#/components/schemas/SmsRequest' + $ref: '#/components/schemas/ApiRequest' application/xml: schema: - $ref: '#/components/schemas/SmsRequest' + $ref: '#/components/schemas/ApiRequest' application/x-www-form-urlencoded: schema: - $ref: '#/components/schemas/SmsRequest' + $ref: '#/components/schemas/ApiRequest' required: true responses: '200': @@ -51,22 +51,22 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/SmsRequest' + $ref: '#/components/schemas/ApiRequest' application/xml: schema: - $ref: '#/components/schemas/SmsRequest' + $ref: '#/components/schemas/ApiRequest' '405': description: Invalid input security: - - sms_auth: - - write:sms - - read:sms + - api_auth: + - write:api + - read:api get: tags: - - sms - summary: Finds SmsRequest + - api + summary: Finds ApiRequest description: Multiple status values can be provided with comma separated strings - operationId: getSmsRequests + operationId: getApiRequests parameters: - name: query in: query @@ -102,29 +102,29 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/SmsRequestPage' + $ref: '#/components/schemas/ApiRequestPage' application/xml: schema: type: array items: - $ref: '#/components/schemas/SmsRequest' + $ref: '#/components/schemas/ApiRequest' '400': description: Invalid status value security: - - sms_auth: - - write:sms - - read:sms - /sms/{smsRequestId}: + - api_auth: + - write:api + - read:api + /api/{apiRequestId}: get: tags: - - sms - summary: Find sms by ID - description: Returns a single sms - operationId: getAnSmsRequest + - api + summary: Find api by ID + description: Returns a single api + operationId: getAnApiRequest parameters: - - name: smsRequestId + - name: apiRequestId in: path - description: ID of sms to return + description: ID of api to return required: true schema: type: string @@ -134,28 +134,28 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/SmsRequest' + $ref: '#/components/schemas/ApiRequest' application/xml: schema: - $ref: '#/components/schemas/SmsRequest' + $ref: '#/components/schemas/ApiRequest' '400': description: Invalid ID supplied '404': - description: Sms Request not found + description: Api Request not found security: - - sms_auth: - - write:sms - - read:sms + - api_auth: + - write:api + - read:api delete: tags: - - sms - summary: Deletes a sms - description: delete a sms - operationId: deleteSmsRequest + - api + summary: Deletes a api + description: delete a api + operationId: deleteApiRequest parameters: - - name: smsRequestId + - name: apiRequestId in: path - description: Sms Request id to delete + description: Api Request id to delete required: true schema: type: string @@ -165,23 +165,23 @@ paths: '404': description: Request not found security: - - sms_auth: - - write:sms - - read:sms + - api_auth: + - write:api + - read:api components: schemas: - SmsRequestValue: + ApiRequestValue: oneOf: - type: string - type: number - - $ref: '#/components/schemas/SmsRequest' - SmsRequest: + - $ref: '#/components/schemas/ApiRequest' + ApiRequest: type: object additionalProperties: - $ref: '#/components/schemas/SmsRequestValue' + $ref: '#/components/schemas/ApiRequestValue' xml: - name: sms_request - SmsRequestPage: + name: api_request + ApiRequestPage: type: object required: - content @@ -190,7 +190,7 @@ components: content: type: array items: - $ref: '#/components/schemas/SmsRequest' + $ref: '#/components/schemas/ApiRequest' meta: $ref: '#/components/schemas/PageMeta' PageMeta: @@ -207,17 +207,17 @@ components: total: type: number requestBodies: - SmsRequest: - description: SmsRequest object that needs to be added to the store + ApiRequest: + description: ApiRequest object that needs to be added to the store content: application/json: schema: - $ref: '#/components/schemas/SmsRequest' + $ref: '#/components/schemas/ApiRequest' application/xml: schema: - $ref: '#/components/schemas/SmsRequest' + $ref: '#/components/schemas/ApiRequest' securitySchemes: - sms_auth: + api_auth: type: apiKey name: api_key in: header \ No newline at end of file diff --git a/package.json b/package.json index 6d0d6b5..37d3b60 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "sms-reader-frontend", - "version": "0.1.0", + "name": "api-reader-frontend", + "version": "0.2.0", "private": true, "dependencies": { "@headlessui/react": "^1.7.13", diff --git a/public/icons/site.webmanifest b/public/icons/site.webmanifest index 3986fe1..814d080 100644 --- a/public/icons/site.webmanifest +++ b/public/icons/site.webmanifest @@ -1,6 +1,6 @@ { - "name": "SMS Request Watcher", - "short_name": "SMS Watcher", + "name": "Request Watcher", + "short_name": "Watcher", "icons": [ { "src": "/icons/android-chrome-192x192.png", diff --git a/public/index.html b/public/index.html index fe9406e..8336835 100644 --- a/public/index.html +++ b/public/index.html @@ -17,9 +17,9 @@ - SMS Request Watcher + API Request Watcher diff --git a/src/components/sms-list-item.tsx b/src/components/api-list-item.tsx similarity index 76% rename from src/components/sms-list-item.tsx rename to src/components/api-list-item.tsx index 6cf7b7a..fff6489 100644 --- a/src/components/sms-list-item.tsx +++ b/src/components/api-list-item.tsx @@ -1,14 +1,14 @@ import React from 'react'; -import { smsApi } from '../store/sms.gen.api'; +import { apiApi } from '../store/api.gen.api'; -interface SmsListItemProps { +interface ApiListItemProps { idx: number; [key: string]: any; } -export function SmsListItem({ id, created_at, idx, ...rest }: SmsListItemProps) { - smsApi.usePrefetch('getAnSmsRequest', {}); +export function ApiListItem({ id, created_at, idx, ...rest }: ApiListItemProps) { + apiApi.usePrefetch('getAnApiRequest', {}); return (
diff --git a/src/components/app-header.tsx b/src/components/app-header.tsx index 9eb5d97..277af4b 100644 --- a/src/components/app-header.tsx +++ b/src/components/app-header.tsx @@ -7,7 +7,7 @@ import { classNames } from '../common/class-names'; const navigation = [ { name: 'Dashboard', href: '/' }, - { name: 'Sms Requests', href: '/sms-requests' } + { name: 'Api Requests', href: '/api-requests' } ]; export function AppHeader() { @@ -24,7 +24,7 @@ export function AppHeader() { SMS API Watcher
diff --git a/src/components/display-api-request-table.tsx b/src/components/display-api-request-table.tsx new file mode 100644 index 0000000..dea33bc --- /dev/null +++ b/src/components/display-api-request-table.tsx @@ -0,0 +1,17 @@ +import React from 'react'; +import { GetApiRequestsApiResponse } from '../store/api.gen.api'; +import { ApiListItem } from './api-list-item'; + +interface DisplayApiRequestTableProps { + response: GetApiRequestsApiResponse; +} + +export default function DisplayApiRequestTable({ response }: DisplayApiRequestTableProps) { + return ( +
+ {response.content.map(({ id, ...rest }, idx) => ( + + ))} +
+ ); +} \ No newline at end of file diff --git a/src/components/display-sms-request-table.tsx b/src/components/display-sms-request-table.tsx deleted file mode 100644 index 9d025b2..0000000 --- a/src/components/display-sms-request-table.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import React from 'react'; -import { GetSmsRequestsApiResponse } from '../store/sms.gen.api'; -import { SmsListItem } from './sms-list-item'; - -interface DisplaySmsRequestTableProps { - response: GetSmsRequestsApiResponse; -} - -export default function DisplaySmsRequestTable({ response }: DisplaySmsRequestTableProps) { - return ( -
- {response.content.map(({ id, ...rest }, idx) => ( - - ))} -
- ); -} \ No newline at end of file diff --git a/src/components/socket.component.tsx b/src/components/socket.component.tsx index 36d7400..b1e0085 100644 --- a/src/components/socket.component.tsx +++ b/src/components/socket.component.tsx @@ -2,7 +2,7 @@ import { socket } from '../service/socket'; import { useEffect } from 'react'; import { setSocketConnection } from '../service/socket.slice'; import { mk } from '../common/keys'; -import { smsApi } from '../store/sms.gen.api'; +import { apiApi } from '../store/api.gen.api'; import { useAppDispatch } from '../service/store'; import * as _ from 'lodash'; @@ -19,8 +19,8 @@ export function SocketComponent() { dispatch(setSocketConnection(true)); }; - const onNewSms = (obj: any) => { - const updateQueryDataThunk = smsApi.util.updateQueryData('getSmsRequests', { + const onNewApi = (obj: any) => { + const updateQueryDataThunk = apiApi.util.updateQueryData('getApiRequests', { page: 0, size }, (data) => { if (!_.includes(data.content, obj)) { @@ -37,13 +37,13 @@ export function SocketComponent() { socket.on('connect', onConnect); socket.on('disconnect', onDisconnect); - socket.on(mk`new_sms_request`, onNewSms); + socket.on(mk`new_api_request`, onNewApi); return () => { socket.off('connect', onConnect); socket.off('disconnect', onDisconnect); - socket.off(mk`new_sms_request`, onNewSms); + socket.off(mk`new_api_request`, onNewApi); }; }, [dispatch]); diff --git a/src/screens/all-sms-requests.screen.tsx b/src/screens/all-api-requests.screen.tsx similarity index 87% rename from src/screens/all-sms-requests.screen.tsx rename to src/screens/all-api-requests.screen.tsx index d69459c..c5cc4af 100644 --- a/src/screens/all-sms-requests.screen.tsx +++ b/src/screens/all-api-requests.screen.tsx @@ -1,14 +1,14 @@ import React, { Fragment, lazy, Suspense, useEffect, useState } from 'react'; import { AppLayout } from '../components/app-layout'; -import { useGetSmsRequestsQuery } from '../store/sms.gen.api'; +import { useGetApiRequestsQuery } from '../store/api.gen.api'; import { AppPagination } from '../components/pagination'; import { useLocation, useNavigate, useSearchParams } from 'react-router-dom'; import { Loading } from '../components/loading'; import { Pagination } from '../types/pagination'; -const DisplaySmsRequestTable = lazy(() => import('../components/display-sms-request-table')); +const DisplayApiRequestTable = lazy(() => import('../components/display-api-request-table')); -export function AllSmsRequestsScreen() { +export function AllApiRequestsScreen() { const navigate = useNavigate(); const location = useLocation(); const [params] = useSearchParams(); @@ -16,7 +16,7 @@ export function AllSmsRequestsScreen() { const [pagination, setPagination] = useState({ page: 0, size: 4 }); - const { data, error, isLoading, isError, isSuccess } = useGetSmsRequestsQuery({ + const { data, error, isLoading, isError, isSuccess } = useGetApiRequestsQuery({ page: pagination.page, size: pagination.size }, { pollingInterval: 60_000, @@ -52,7 +52,7 @@ export function AllSmsRequestsScreen() { }); return ( - + {isLoading && ( Loading... @@ -68,7 +68,7 @@ export function AllSmsRequestsScreen() { {isSuccess && ( }> - + )} diff --git a/src/screens/single-sms-request.screen.tsx b/src/screens/single-api-request.screen.tsx similarity index 61% rename from src/screens/single-sms-request.screen.tsx rename to src/screens/single-api-request.screen.tsx index 5571623..86aa1ab 100644 --- a/src/screens/single-sms-request.screen.tsx +++ b/src/screens/single-api-request.screen.tsx @@ -1,9 +1,9 @@ import { AppLayout } from '../components/app-layout'; import React from 'react'; -export function SingleSmsRequestScreen() { +export function SingleApiRequestScreen() { return ( - + Single ); diff --git a/src/service/router.tsx b/src/service/router.tsx index ae1789c..3104c19 100644 --- a/src/service/router.tsx +++ b/src/service/router.tsx @@ -12,15 +12,15 @@ export const router = createBrowserRouter([ { path: '', // https://reactrouter.com/en/main/components/navigate - Component: () => + Component: () => }, { - path: 'sms-requests', - lazy: () => import('../screens/all-sms-requests.screen').then((m) => ({ Component: m.AllSmsRequestsScreen })) + path: 'api-requests', + lazy: () => import('../screens/all-api-requests.screen').then((m) => ({ Component: m.AllApiRequestsScreen })) }, { - path: 'sms-requests/:request_id', - lazy: () => import('../screens/single-sms-request.screen').then((m) => ({ Component: m.SingleSmsRequestScreen })) + path: 'api-requests/:request_id', + lazy: () => import('../screens/single-api-request.screen').then((m) => ({ Component: m.SingleApiRequestScreen })) } ] } diff --git a/yarn.lock b/yarn.lock index 965ccde..e286c56 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7875,16 +7875,11 @@ prettier-linter-helpers@^1.0.0: dependencies: fast-diff "^1.1.2" -prettier@^2.2.1: +prettier@^2.2.1, prettier@^2.8.7: version "2.8.7" resolved "https://registry.npmjs.org/prettier/-/prettier-2.8.7.tgz" integrity sha512-yPngTo3aXUUmyuTjeTUT75txrf+aMh9FiD7q9ZE/i6r0bPb22g4FsE6Y338PQX1bmfy08i9QQCB7/rcUAVntfw== -prettier@^2.8.7: - version "2.8.7" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.7.tgz#bb79fc8729308549d28fe3a98fce73d2c0656450" - integrity sha512-yPngTo3aXUUmyuTjeTUT75txrf+aMh9FiD7q9ZE/i6r0bPb22g4FsE6Y338PQX1bmfy08i9QQCB7/rcUAVntfw== - pretty-bytes@^5.3.0, pretty-bytes@^5.4.1: version "5.6.0" resolved "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz"