-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(slices): Remove renameSliceSaga
- Loading branch information
1 parent
043c3a4
commit 343c771
Showing
11 changed files
with
109 additions
and
174 deletions.
There are no files selected for viewing
54 changes: 33 additions & 21 deletions
54
packages/slice-machine/components/Forms/RenameSliceModal/RenameSliceModal.tsx
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
37 changes: 37 additions & 0 deletions
37
packages/slice-machine/src/features/slices/actions/renameSlice.ts
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 @@ | ||
import { toast } from "react-toastify"; | ||
|
||
import { managerClient } from "@src/managerClient"; | ||
import { ComponentUI } from "@lib/models/common/ComponentUI"; | ||
import { rename } from "@src/domain/slice"; | ||
import { Slices } from "@lib/models/common/Slice"; | ||
|
||
type DeleteSliceArgs = { | ||
newSliceName: string; | ||
slice: ComponentUI; | ||
onSuccess: (renamedSlice: ComponentUI) => void; | ||
}; | ||
|
||
export async function renameSlice(args: DeleteSliceArgs) { | ||
const { slice, newSliceName, onSuccess } = args; | ||
|
||
try { | ||
const renamedSlice = rename(slice, newSliceName); | ||
|
||
const { errors } = await managerClient.slices.renameSlice({ | ||
libraryID: slice.from, | ||
model: Slices.fromSM(renamedSlice.model), | ||
}); | ||
|
||
if (errors.length > 0) { | ||
throw errors; | ||
} | ||
|
||
onSuccess(renamedSlice); | ||
|
||
toast.success("Slice name updated"); | ||
} catch (e) { | ||
const errorMessage = `An unexpected error happened while renaming “${slice.model.name}”.`; | ||
console.error(errorMessage, e); | ||
toast.error(errorMessage); | ||
} | ||
} |
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
Oops, something went wrong.