Skip to content

Commit

Permalink
fix: no redirects after save and successfully save messages (#152)
Browse files Browse the repository at this point in the history
* fix: no redirects after save and successfully save messages
  • Loading branch information
danilolutz authored Feb 18, 2022
1 parent 87b127b commit 416efc0
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"url": "https://github.com/librarian-org/librarian/issues"
},
"productName": "librarian",
"version": "1.0.0",
"version": "1.0.0-alpha",
"description": "The Librarian app is ideal for schools libraries and for someone who have many books.",
"main": ".webpack/main",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions src/app/components/Person/Create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ const CreatePerson: React.FC = () => {
},
}) as Person;

addToast({
title: i18n.t('notifications.success'),
type: 'success',
description: i18n
.t('person.successSave'),
});

trigger(AppEvent.personTab, {
action: Actions.read,
value: insertedPerson,
Expand Down
8 changes: 8 additions & 0 deletions src/app/components/Person/Update/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,14 @@ const PersonUpdate: React.FC<{ item: Person }> = ({ item }) => {
},
},
}) as Person;

addToast({
title: i18n.t('notifications.success'),
type: 'success',
description: i18n
.t('person.successSave'),
});

trigger(AppEvent.personTab, {
action: Actions.read,
value: insertedPerson,
Expand Down
55 changes: 36 additions & 19 deletions src/app/components/Tabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ interface Event {
const Tabs: React.FC = () => {
const [tabItems, setTabItems] = useState<Tab[]>([]);
const [activeTab, setActiveTab] = useState<Tab>(null);
const [selectedTab, setSelectedTab] = useState<Tab>(null);
const [isOpen, setOpen] = useState(false);
const [action, setAction] = useState('list');
// const [item, setItem] = useState(undefined);
const [, setAction] = useState('list');

const lastTab = useCallback((): Tab => {
return tabItems[tabItems.length - 1];
Expand Down Expand Up @@ -79,11 +79,11 @@ const Tabs: React.FC = () => {

const tabAlreadyOpened = tabItems.filter((t) => t.type === type);
if (tabAlreadyOpened.length > 0) {
setAction(action);
tabAlreadyOpened[0].action = action;
tabAlreadyOpened[0].item = item;
setAction(action);
setTabItems(tabItems);
setActiveTab(tabAlreadyOpened[0]);
setSelectedTab(tabAlreadyOpened[0]);
return;
}

Expand All @@ -92,7 +92,7 @@ const Tabs: React.FC = () => {
type: type,
title: `${type}.label`,
action: action,
item: undefined
item: undefined,
};

addTab(tab);
Expand Down Expand Up @@ -123,20 +123,29 @@ const Tabs: React.FC = () => {
}
}, [activeTab, close]);

const borrowTab = useCallback((params: CustomEvent<ActionParameter>) => {
const { action, value } = params.detail;
handleCreateTab('borrow', action, value);
}, [handleCreateTab]);
const borrowTab = useCallback(
(params: CustomEvent<ActionParameter>) => {
const { action, value } = params.detail;
handleCreateTab('borrow', action, value);
},
[handleCreateTab]
);

const personTab = useCallback((params: CustomEvent<ActionParameter>) => {
const { action, value } = params.detail;
handleCreateTab('person', action, value);
}, [handleCreateTab]);
const personTab = useCallback(
(params: CustomEvent<ActionParameter>) => {
const { action, value } = params.detail;
handleCreateTab('person', action, value);
},
[handleCreateTab]
);

const titleTab = useCallback((params: CustomEvent<ActionParameter>) => {
const { action, value } = params.detail;
handleCreateTab('title', action, value);
}, [handleCreateTab]);
const titleTab = useCallback(
(params: CustomEvent<ActionParameter>) => {
const { action, value } = params.detail;
handleCreateTab('title', action, value);
},
[handleCreateTab]
);

const settingsTab = useCallback(() => {
handleCreateTab('settings', Actions.update, {});
Expand Down Expand Up @@ -185,6 +194,10 @@ const Tabs: React.FC = () => {
[tabItems]
);

useEffect(()=>{
setActiveTab(selectedTab);
}, [selectedTab]);

const rendererTabs = (tab: Tab, index: number, isActive: boolean) => {
return (
<TabHeader
Expand Down Expand Up @@ -221,8 +234,12 @@ const Tabs: React.FC = () => {
key={`tab-content-${tab.id}`}
>
{tab.type === 'borrow' && <Borrow />}
{tab.type === 'person' && <Person action={tab.action} item={tab.item}/>}
{tab.type === 'title' && <Title action={tab.action} item={tab.item} />}
{tab.type === 'person' && (
<Person action={tab.action} item={tab.item} />
)}
{tab.type === 'title' && (
<Title action={tab.action} item={tab.item} />
)}
{tab.type === 'settings' && <Settings />}
</TabContent>
)
Expand Down
7 changes: 7 additions & 0 deletions src/app/components/Title/Create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ const TitleCreate: React.FC = () => {
},
}) as Title;

addToast({
title: i18n.t('notifications.success'),
type: 'success',
description: i18n
.t('title.successSave'),
});

trigger(AppEvent.titleTab, { action: Actions.read, value: insertedTitle });
}, [addToast, authors, categories, isbn, publishers, title]);

Expand Down
7 changes: 7 additions & 0 deletions src/app/components/Title/Update/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ const TitleUpdate: React.FC<{ item: Title }> = ({ item }) => {
},
}) as Title;

addToast({
title: i18n.t('notifications.success'),
type: 'success',
description: i18n
.t('title.successSave'),
});

trigger(AppEvent.titleTab, { action: Actions.read, value: updatedTitle });
}, [addToast, authors, categories, isbn, item, publishers, title]);

Expand Down
6 changes: 4 additions & 2 deletions src/locales/en-US/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@

"edit": "Edit",

"invalidISBN": "Invalid ISBN"
"invalidISBN": "Invalid ISBN",
"successSave": "Title saved successfully "
},
"settings": {
"label": "Settings",
Expand Down Expand Up @@ -230,7 +231,8 @@
"informError": "Please provide information to create person: #errors#",
"informErrorsContact": "Please provide information to a contact: #errors#",
"informErrorsAddress": "Please profive information to a address: #errors#",
"hasBeenAdd": "This contact already been added"
"hasBeenAdd": "This contact already been added",
"successSave": "Person saved successfully"
},
"address":{
"number": "Number",
Expand Down
6 changes: 4 additions & 2 deletions src/locales/pt-BR/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@

"edit": "Editar",

"invalidISBN": "ISBN inválido"
"invalidISBN": "ISBN inválido",
"successSave": "Título salvo com sucesso"
},
"settings": {
"label": "Configurações",
Expand Down Expand Up @@ -232,7 +233,8 @@
"informError": "Por favor forneça as informações para criar a pessoa: #errors#",
"informErrorsContact": "Por favor forneça informação do contato: #errors#",
"informErrorsAddress": "Por favor forneça informação de endereço: #errors#",
"hasBeenAdd": "Este contato já foi adicionado"
"hasBeenAdd": "Este contato já foi adicionado",
"successSave": "Registro da Pessoa salvo com sucesso"
},
"address":{
"zipcode": "CEP",
Expand Down

0 comments on commit 416efc0

Please sign in to comment.