Skip to content

Commit

Permalink
remove toast
Browse files Browse the repository at this point in the history
  • Loading branch information
jamalsoueidan committed Jul 12, 2024
1 parent 3422cb8 commit 8e12769
Show file tree
Hide file tree
Showing 22 changed files with 50 additions and 204 deletions.
43 changes: 4 additions & 39 deletions app/routes/account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import {
} from '@remix-run/react';
import {json, type LoaderFunctionArgs} from '@shopify/remix-oxygen';
import {type CustomerFragment} from 'customer-accountapi.generated';
import {useEffect} from 'react';
import notify, {Toaster} from 'react-hot-toast';
import {getToast} from 'remix-toast';
import {CUSTOMER_DETAILS_QUERY} from '~/graphql/customer-account/CustomerDetailsQuery';
import {type User} from '~/lib/api/model';

Expand Down Expand Up @@ -52,49 +49,17 @@ export async function loader({context, request}: LoaderFunctionArgs) {
throw new Error('Customer not found');
}

const {toast} = await getToast(request);

return json(
{
customer: data.customer,
toast,
},
{
headers: {
'Cache-Control': 'no-cache, no-store, must-revalidate',
'Set-Cookie': await context.session.commit(),
},
},
);
return json({
customer: data.customer,
});
}

export default function Acccount() {
const {customer, toast} = useLoaderData<typeof loader>();

useEffect(() => {
if (toast) {
switch (toast.type) {
case 'success':
notify.success(toast.message);
return;
case 'error':
notify.error(toast.message);

return;
default:
return;
}
}
}, [toast]);
const {customer} = useLoaderData<typeof loader>();

return (
<>
<Outlet context={{customer}} />
<Toaster
position="top-center"
reverseOrder={false}
toastOptions={{duration: 3000, className: 'toast', id: 'toast'}}
/>
</>
);
}
5 changes: 1 addition & 4 deletions app/routes/business.booked.$blockedId.destroy.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {redirect, type ActionFunction} from '@shopify/remix-oxygen';
import {redirectWithSuccess} from 'remix-toast';
import {getBookingShopifyApi} from '~/lib/api/bookingShopifyApi';
import {getCustomer} from '~/lib/get-customer';

Expand All @@ -12,9 +11,7 @@ export const action: ActionFunction = async ({context, params}) => {
params.blockedId || '',
);

return redirectWithSuccess('/business/booked', {
message: 'Ferie er nu slettet!',
});
return redirect('/business/booked');
} catch (error) {
return redirect('/business/booked');
}
Expand Down
7 changes: 2 additions & 5 deletions app/routes/business.booked.create.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {getFormProps, getInputProps, useForm} from '@conform-to/react';
import {parseWithZod} from '@conform-to/zod';
import {FocusTrap, Modal, Stack, TextInput} from '@mantine/core';
import {Form, useActionData} from '@remix-run/react';
import {Form, redirect, useActionData} from '@remix-run/react';
import type {ActionFunctionArgs} from 'react-router';
import {redirectWithSuccess} from 'remix-toast';
import {type z} from 'zod';
import DateTimeInput from '~/components/form/DateTimeInput';
import {SubmitButton} from '~/components/form/SubmitButton';
Expand All @@ -29,9 +28,7 @@ export const action = async ({request, context}: ActionFunctionArgs) => {
submission.value,
);

return redirectWithSuccess('/business/booked', {
message: 'Ferie er nu tilføjet!',
});
return redirect('/business/booked');
} catch (error) {
return submission.reply();
}
Expand Down
6 changes: 2 additions & 4 deletions app/routes/business.locations.$locationId._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {Form, Link, useActionData, useLoaderData} from '@remix-run/react';

import {
json,
redirect,
type ActionFunctionArgs,
type LoaderFunctionArgs,
} from '@shopify/remix-oxygen';
Expand All @@ -17,7 +18,6 @@ import {customerLocationUpdateBody} from '~/lib/zod/bookingShopifyApi';

import {parseWithZod} from '@conform-to/zod';
import {Anchor, Group, Stack, Text, TextInput} from '@mantine/core';
import {redirectWithSuccess} from 'remix-toast';
import {AddressAutocompleteInput} from '~/components/form/AddressAutocompleteInput';
import {NumericInput} from '~/components/form/NumericInput';
import {SubmitButton} from '~/components/form/SubmitButton';
Expand Down Expand Up @@ -59,9 +59,7 @@ export const action = async ({
`${baseURL}/customer/${customerId}/locations`,
);

return redirectWithSuccess('.', {
message: 'Lokation er opdateret!',
});
return redirect('.');
} catch (error) {
return submission.reply();
}
Expand Down
7 changes: 2 additions & 5 deletions app/routes/business.locations.$locationId.destroy.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {type ActionFunction} from '@shopify/remix-oxygen';
import {redirectWithSuccess} from 'remix-toast';
import {redirect, type ActionFunction} from '@shopify/remix-oxygen';
import {getBookingShopifyApi} from '~/lib/api/bookingShopifyApi';
import {baseURL} from '~/lib/api/mutator/query-client';
import {getCustomer} from '~/lib/get-customer';
Expand All @@ -22,7 +21,5 @@ export const action: ActionFunction = async ({context, params}) => {
),
]);

return redirectWithSuccess('/business/locations', {
message: 'Lokation er slettet!!',
});
return redirect('/business/locations');
};
5 changes: 2 additions & 3 deletions app/routes/business.locations.$locationId.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {Form, Link, Outlet, useLoaderData} from '@remix-run/react';

import {type LoaderFunctionArgs} from '@shopify/remix-oxygen';
import {json, type LoaderFunctionArgs} from '@shopify/remix-oxygen';
import {getBookingShopifyApi} from '~/lib/api/bookingShopifyApi';
import {getCustomer} from '~/lib/get-customer';

import {Button, Container, rem} from '@mantine/core';
import {jsonWithSuccess} from 'remix-toast';
import {AccountButton} from '~/components/account/AccountButton';
import {AccountContent} from '~/components/account/AccountContent';
import {AccountTitle} from '~/components/account/AccountTitle';
Expand All @@ -24,7 +23,7 @@ export async function loader({context, params}: LoaderFunctionArgs) {
context,
);

return jsonWithSuccess(response.payload, {message: 'Location er opdateret!'});
return json(response.payload);
}

export default function AccountLocationsEdit() {
Expand Down
6 changes: 2 additions & 4 deletions app/routes/business.locations.create.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Form, useActionData, useLoaderData} from '@remix-run/react';
import {
json,
redirect,
type ActionFunctionArgs,
type LoaderFunctionArgs,
} from '@shopify/remix-oxygen';
Expand All @@ -16,7 +17,6 @@ import {
} from '@conform-to/react';
import {parseWithZod} from '@conform-to/zod';
import {Container, rem, Stack, TextInput} from '@mantine/core';
import {redirectWithSuccess} from 'remix-toast';
import {AccountContent} from '~/components/account/AccountContent';
import {AccountTitle} from '~/components/account/AccountTitle';
import {AddressAutocompleteInput} from '~/components/form/AddressAutocompleteInput';
Expand Down Expand Up @@ -49,9 +49,7 @@ export const action = async ({request, context}: ActionFunctionArgs) => {
`${baseURL}/customer/${customerId}/locations`,
);

return redirectWithSuccess('/business/locations', {
message: 'Lokation er nu oprettet!',
});
return redirect('/business/locations');
} catch (error) {
return submission.reply();
}
Expand Down
21 changes: 7 additions & 14 deletions app/routes/business.public._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Stack, Text, TextInput, rem} from '@mantine/core';
import {Form, useActionData, useLoaderData} from '@remix-run/react';
import {
json,
redirect,
type ActionFunctionArgs,
type LoaderFunctionArgs,
} from '@shopify/remix-oxygen';
Expand All @@ -16,10 +17,10 @@ import {
import {parseWithZod} from '@conform-to/zod';

import {useTranslation} from 'react-i18next';
import {redirectWithSuccess} from 'remix-toast';
import {MultiTags} from '~/components/form/MultiTags';
import {RadioGroup} from '~/components/form/RadioGroup';
import {SubmitButton} from '~/components/form/SubmitButton';
import {useProfessionAndSkills} from '~/components/ProfessionButton';
import {TextEditor} from '~/components/richtext/TextEditor';
import {getBookingShopifyApi} from '~/lib/api/bookingShopifyApi';
import {convertHTML} from '~/lib/convertHTML';
Expand All @@ -44,9 +45,7 @@ export const action = async ({request, context}: ActionFunctionArgs) => {
aboutMeHtml: convertHTML(submission.value.aboutMe),
});

return redirectWithSuccess('/business/public', {
message: 'Profil er opdateret!',
});
return redirect('/business/public');
} catch (error) {
return submission.reply();
}
Expand All @@ -57,20 +56,14 @@ export async function loader({context}: LoaderFunctionArgs) {

const {payload: user} = await getBookingShopifyApi().customerGet(customerId);

const {payload: professionOptions} =
await getBookingShopifyApi().metaProfessions();

const {payload: specialityOptions} =
await getBookingShopifyApi().metaspecialties();

return json({user, professionOptions, specialityOptions});
return json({user});
}

export default function AccountBusiness() {
const {t} = useTranslation(['global']);
const lastResult = useActionData<typeof action>();
const {user, professionOptions, specialityOptions} =
useLoaderData<typeof loader>();
const {professionOptions, skillsOptions} = useProfessionAndSkills();
const {user} = useLoaderData<typeof loader>();

const [
form,
Expand Down Expand Up @@ -125,7 +118,7 @@ export default function AccountBusiness() {

<MultiTags
field={specialties}
data={specialityOptions}
data={skillsOptions}
label="Hvad er dine specialer?"
placeholder="Vælge special(er)?"
/>
Expand Down
6 changes: 2 additions & 4 deletions app/routes/business.public.social.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import {Stack, TextInput, rem} from '@mantine/core';
import {Form, useActionData, useLoaderData} from '@remix-run/react';
import {
json,
redirect,
type ActionFunctionArgs,
type LoaderFunctionArgs,
} from '@shopify/remix-oxygen';

import {getFormProps, getInputProps, useForm} from '@conform-to/react';
import {parseWithZod} from '@conform-to/zod';
import {IconAt} from '@tabler/icons-react';
import {redirectWithSuccess} from 'remix-toast';
import {SubmitButton} from '~/components/form/SubmitButton';
import {getBookingShopifyApi} from '~/lib/api/bookingShopifyApi';
import {getCustomer} from '~/lib/get-customer';
Expand All @@ -32,9 +32,7 @@ export const action = async ({request, context}: ActionFunctionArgs) => {
try {
await getBookingShopifyApi().customerUpdate(customerId, submission.value);

return redirectWithSuccess('.', {
message: 'Social er opdateret!',
});
return redirect('.');
} catch (error) {
return submission.reply();
}
Expand Down
6 changes: 2 additions & 4 deletions app/routes/business.public.theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {
import {Form, useActionData, useLoaderData} from '@remix-run/react';
import {
json,
redirect,
type ActionFunctionArgs,
type LoaderFunctionArgs,
} from '@shopify/remix-oxygen';

import {getFormProps, useForm, useInputControl} from '@conform-to/react';
import {parseWithZod} from '@conform-to/zod';
import {IconCheck} from '@tabler/icons-react';
import {redirectWithSuccess} from 'remix-toast';
import {SubmitButton} from '~/components/form/SubmitButton';
import {getBookingShopifyApi} from '~/lib/api/bookingShopifyApi';
import {getCustomer} from '~/lib/get-customer';
Expand All @@ -38,9 +38,7 @@ export const action = async ({request, context}: ActionFunctionArgs) => {
try {
await getBookingShopifyApi().customerUpdate(customerId, submission.value);

return redirectWithSuccess('.', {
message: 'Tema er opdateret!',
});
return redirect('.');
} catch (error) {
return submission.reply();
}
Expand Down
6 changes: 2 additions & 4 deletions app/routes/business.public.upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import {
} from '@remix-run/react';
import {
json,
redirect,
type ActionFunctionArgs,
type LoaderFunctionArgs,
} from '@shopify/remix-oxygen';
import {IconFileCv, IconInfoCircle} from '@tabler/icons-react';
import {useEffect, useRef, useState} from 'react';
import {redirectWithSuccess} from 'remix-toast';
import {getBookingShopifyApi} from '~/lib/api/bookingShopifyApi';
import {getCustomer} from '~/lib/get-customer';

Expand Down Expand Up @@ -41,9 +41,7 @@ export const action = async ({
resourceUrl,
});

return redirectWithSuccess('.', {
message: 'Der kan gå få sekunder inden dit billed bliver opdateret!',
});
return redirect('.');
};

export async function loader({context}: LoaderFunctionArgs) {
Expand Down
7 changes: 2 additions & 5 deletions app/routes/business.schedules.$scheduleHandle.destroy.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {type ActionFunction} from '@shopify/remix-oxygen';
import {redirectWithSuccess} from 'remix-toast';
import {redirect, type ActionFunction} from '@shopify/remix-oxygen';

import {getBookingShopifyApi} from '~/lib/api/bookingShopifyApi';
import {baseURL} from '~/lib/api/mutator/query-client';
Expand All @@ -26,7 +25,5 @@ export const action: ActionFunction = async ({context, params}) => {
`${baseURL}/customer/${customerId}/schedules`,
);

return redirectWithSuccess('/business/schedules', {
message: 'Vagtplanen er slettet!',
});
return redirect('/business/schedules');
};
6 changes: 2 additions & 4 deletions app/routes/business.schedules.$scheduleHandle.edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Form, useActionData, useLoaderData} from '@remix-run/react';

import {
json,
redirect,
type ActionFunctionArgs,
type LoaderFunctionArgs,
} from '@shopify/remix-oxygen';
Expand All @@ -12,7 +13,6 @@ import {customerScheduleCreateBody} from '~/lib/zod/bookingShopifyApi';

import {parseWithZod} from '@conform-to/zod';
import {FocusTrap, Stack, TextInput} from '@mantine/core';
import {redirectWithSuccess} from 'remix-toast';
import {SubmitButton} from '~/components/form/SubmitButton';
import {baseURL} from '~/lib/api/mutator/query-client';

Expand Down Expand Up @@ -52,9 +52,7 @@ export const action = async ({
`${baseURL}/customer/${customerId}/schedules`,
);

return redirectWithSuccess(`/business/schedules/${response.payload._id}`, {
message: 'Vagtplan er opdateret!',
});
return redirect(`/business/schedules/${response.payload._id}`);
} catch (error) {
return submission.reply();
}
Expand Down
Loading

0 comments on commit 8e12769

Please sign in to comment.