Skip to content

Commit

Permalink
Merge pull request #12 from Code-Forge-Net/7-add-description-field-to…
Browse files Browse the repository at this point in the history
…-toastmessage

7 add description field to toastmessage
  • Loading branch information
AlemTuzlak authored Feb 18, 2024
2 parents 8f5783e + 4f59826 commit c46f4be
Show file tree
Hide file tree
Showing 10 changed files with 336 additions and 74 deletions.
52 changes: 50 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,50 @@ export default function App() {

![react-toastify](./assets/sonner.gif)

## Overriding cookie options

You can override the default cookie options by passing in your own options via the `setToastCookieOptions` function.

```tsx
import { setToastCookieOptions } from "remix-toast";

setToastCookieOptions({
secrets:
process.env.NODE_ENV === "production"
? [process.env.SESSION_SECRET]
: ["secret"]
});
```

## Creating utility functions with custom sessions

`createToastUtilsWithCustomSession` is a function that allows you to create a custom session for your toasts. This is useful if you want to have different types of toasts for different parts of your app.

```tsx
import { createCookieSessionStorage } from "@remix-run/node";
import { createToastUtilsWithCustomSession } from "remix-toast";

const session = createCookieSessionStorage({
cookie: {
name: "your-custom-session",
secrets: ["some-secret"],
},
});

export const {
useToast,
redirectWithToast,
redirectWithSuccess,
redirectWithError,
redirectWithInfo,
redirectWithWarning,
jsonWithSuccess,
jsonWithError,
jsonWithInfo,
jsonWithWarning
} = createToastUtilsWithCustomSession(session);
```

## Utilities

### redirectWithToast
Expand All @@ -154,7 +198,7 @@ General function that allows you to redirect to a new route and show a toast mes
import { redirectWithToast } from "remix-toast";

export const action = () => {
return redirectWithToast("/login", { message: "You need to login to access this page", type: "error" });
return redirectWithToast("/login", { message: "You need to login to access this page", description: "description of toast", type: "error" });
}

```
Expand All @@ -167,7 +211,9 @@ Redirects to a new route and shows a success toast message.
import { redirectWithSuccess } from "remix-toast";

export const action = () => {
return redirectWithSuccess("/login", "You are logged in!");
return redirectWithSuccess("/login", "You are logged in!");
//or with description and message (works for all the other utilities as well)
return redirectWithSuccess("/login", { message: "You are logged in!", description: "description of toast" });
}

```
Expand Down Expand Up @@ -218,6 +264,8 @@ import { jsonWithSuccess } from "remix-toast";

export const action = () => {
return jsonWithSuccess({ result: "Data saved successfully" }, "Operation successful! 🎉");
//or with description and message (works for all the other utilities as well)
return jsonWithSuccess({ result: "Data saved successfully" }, { message: "Operation successful! 🎉", description: "description of toast" });
};
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "remix-toast",
"version": "1.1.0",
"version": "1.2.0",
"description": "Utility functions for server-side toast notifications",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
Loading

0 comments on commit c46f4be

Please sign in to comment.