-
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
bac62a7
commit afcf363
Showing
12 changed files
with
128 additions
and
184 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
57 changes: 36 additions & 21 deletions
57
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 = { | ||
slice: ComponentUI; | ||
newSliceName: string; | ||
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(`Successfully renamed slice name to “${newSliceName}”`); | ||
} catch (e) { | ||
const errorMessage = `An unexpected error happened while renaming “${newSliceName}”.`; | ||
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
Oops, something went wrong.