-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* react-hooks * add readme * 2022 * restore readme * fix types * fix types
- Loading branch information
1 parent
c66337d
commit 7eae37a
Showing
32 changed files
with
772 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Courier | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
|
||
- [Overview](#overview) | ||
- [Types](#types) | ||
|
||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
|
||
<a name="0overviewmd"></a> | ||
|
||
### [Overview](#overview) | ||
|
||
`@trycourier/react-hooks` exist as a separate package so that you can build your own interface using our api and state management without having to install all the dependencies that `@trycourier/react-inbox` or other `react-dom` based packages include. | ||
|
||
This also enables using this package with `react-native` in a much simpler way. | ||
|
||
<a name="1typesmd"></a> | ||
|
||
### [Types](#types) | ||
|
||
``` | ||
const inbox: IInbox & IInboxActions = useInbox(); | ||
interface ITab { | ||
filters: { | ||
isRead?: boolean; | ||
}; | ||
label: string; | ||
id: string; | ||
} | ||
interface IMessage { | ||
unread?: number; | ||
messageId: string; | ||
created: number; | ||
title: string; | ||
body: string; | ||
blocks?: Array<IActionBlock | ITextBlock>; | ||
icon?: string; | ||
read?: boolean; | ||
data?: { | ||
clickAction: string; | ||
}; | ||
trackingIds?: { | ||
clickTrackingId: string; | ||
deliveredTrackingId: string; | ||
readTrackingId: string; | ||
unreadTrackingId: string; | ||
}; | ||
} | ||
interface IInboxActions { | ||
init: (inbox: IInbox) => void; | ||
toggleInbox: (isOpen?: boolean) => void; | ||
setView: (view: "messages" | "preferences") => void; | ||
setCurrentTab: (newTab: ITab) => void; | ||
fetchMessages: (params?: IFetchMessagesParams) => void; | ||
getMessageCount: (params?: IGetMessagesParams) => void; | ||
markMessageRead: (messageId: string, trackingId: string) => Promise<void>; | ||
markMessageUnread: (messageId: string, trackingId: string) => Promise<void>; | ||
markAllAsRead: () => void; | ||
} | ||
interface IInbox { | ||
isOpen?: boolean; | ||
tabs?: ITab[]; | ||
currentTab?: ITab; | ||
isLoading?: boolean; | ||
messages?: Array<IMessage>; | ||
startCursor?: string; | ||
unreadMessageCount?: number; | ||
view?: "messages" | "preferences"; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module.exports = { | ||
sourceType: "unambiguous", | ||
plugins: [ | ||
"inline-react-svg", | ||
"@babel/transform-runtime", | ||
"babel-plugin-styled-components", | ||
"transform-inline-environment-variables", | ||
"transform-class-properties", | ||
[ | ||
"babel-plugin-inline-import", | ||
{ | ||
extensions: [".css"], | ||
}, | ||
], | ||
["babel-plugin-react-remove-properties", { properties: ["data-testid"] }], | ||
[ | ||
"babel-plugin-root-import", | ||
{ | ||
root: __dirname, | ||
rootPathSuffix: "./src", | ||
rootPathPrefix: "~/", | ||
}, | ||
], | ||
].filter(Boolean), | ||
presets: [ | ||
"@babel/preset-typescript", | ||
"@babel/preset-env", | ||
"@babel/preset-react", | ||
], | ||
ignore: ["src/__tests__", "src/__mocks__"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
### [Overview](#overview) | ||
|
||
`@trycourier/react-hooks` exist as a separate package so that you can build your own interface using our api and state management without having to install all the dependencies that `@trycourier/react-inbox` or other `react-dom` based packages include. | ||
|
||
This also enables using this package with `react-native` in a much simpler way. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
### [Types](#types) | ||
|
||
``` | ||
const inbox: IInbox & IInboxActions = useInbox(); | ||
interface ITab { | ||
filters: { | ||
isRead?: boolean; | ||
}; | ||
label: string; | ||
id: string; | ||
} | ||
interface IMessage { | ||
unread?: number; | ||
messageId: string; | ||
created: number; | ||
title: string; | ||
body: string; | ||
blocks?: Array<IActionBlock | ITextBlock>; | ||
icon?: string; | ||
read?: boolean; | ||
data?: { | ||
clickAction: string; | ||
}; | ||
trackingIds?: { | ||
clickTrackingId: string; | ||
deliveredTrackingId: string; | ||
readTrackingId: string; | ||
unreadTrackingId: string; | ||
}; | ||
} | ||
interface IInboxActions { | ||
init: (inbox: IInbox) => void; | ||
toggleInbox: (isOpen?: boolean) => void; | ||
setView: (view: "messages" | "preferences") => void; | ||
setCurrentTab: (newTab: ITab) => void; | ||
fetchMessages: (params?: IFetchMessagesParams) => void; | ||
getMessageCount: (params?: IGetMessagesParams) => void; | ||
markMessageRead: (messageId: string, trackingId: string) => Promise<void>; | ||
markMessageUnread: (messageId: string, trackingId: string) => Promise<void>; | ||
markAllAsRead: () => void; | ||
} | ||
interface IInbox { | ||
isOpen?: boolean; | ||
tabs?: ITab[]; | ||
currentTab?: ITab; | ||
isLoading?: boolean; | ||
messages?: Array<IMessage>; | ||
startCursor?: string; | ||
unreadMessageCount?: number; | ||
view?: "messages" | "preferences"; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module.exports = { | ||
// The root of your source code, typically /src | ||
// `<rootDir>` is a token Jest substitutes | ||
roots: ["<rootDir>"], | ||
|
||
globals: { | ||
"ts-jest": { | ||
babelConfig: require("./babel.config.js"), | ||
}, | ||
}, | ||
|
||
// Jest transformations -- this adds support for TypeScript | ||
// using ts-jest | ||
transform: { | ||
"\\.(ts|tsx)$": "ts-jest", | ||
}, | ||
|
||
// Runs special logic, such as cleaning up components | ||
// when using React Testing Library and adds special | ||
// extended assertions to Jest | ||
setupFilesAfterEnv: ["@testing-library/jest-dom/extend-expect"], | ||
|
||
// Test spec file resolution pattern | ||
// Matches parent folder `__tests__` and filename | ||
// should contain `test` or `spec`. | ||
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$", | ||
|
||
// Module file extensions for importing | ||
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], | ||
moduleNameMapper: { | ||
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": | ||
"<rootDir>/__mocks__/fileMock.js", | ||
"\\.(scss|sass|css)$": "identity-obj-proxy", | ||
"~(.*)$": "<rootDir>/src/$1", | ||
}, | ||
testPathIgnorePatterns: ["/node_modules/", "helpers"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "@trycourier/react-hooks", | ||
"version": "1.14.2", | ||
"description": "", | ||
"main": "dist/index.js", | ||
"types": "typings/index.d.ts", | ||
"scripts": { | ||
"babel": "babel src -d dist --extensions \".ts,.tsx\" --ignore \"src/**/__tests__/**\"", | ||
"build:watch": "yarn babel --watch", | ||
"build": "rimraf dist && yarn babel", | ||
"clean": "rimraf dist", | ||
"test": "jest -c jest.config.js --runInBand --silent", | ||
"type-check": "tsc --noEmit", | ||
"readme": "concat-md --toc --decrease-title-levels --dir-name-as-title docs > README.md", | ||
"types": "tsc --declaration --outDir typings/ --emitDeclarationOnly --declarationMap --allowJs false --checkJs false" | ||
}, | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@types/deep-extend": "^0.4.32", | ||
"concat-md": "^0.3.5" | ||
}, | ||
"dependencies": { | ||
"@trycourier/client-graphql": "^1.14.2", | ||
"@trycourier/react-provider": "^1.14.2", | ||
"deep-extend": "^0.6.0", | ||
"rimraf": "^3.0.2" | ||
}, | ||
"peerDependencies": { | ||
"react": "^17.0.1" | ||
}, | ||
"files": [ | ||
"dist/", | ||
"typings/" | ||
], | ||
"exports": { | ||
".": "./dist/index.js", | ||
"./use-inbox": "./dist/inbox/use-inbox.js" | ||
} | ||
} |
Oops, something went wrong.